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