LCOV - code coverage report
Current view: top level - libreoffice/sd/source/core - CustomAnimationPreset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 130 265 49.1 %
Date: 2012-12-27 Functions: 10 23 43.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/util/XCloneable.hpp>
      21             : #include <com/sun/star/util/XMacroExpander.hpp>
      22             : #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
      23             : #include <com/sun/star/container/XNameAccess.hpp>
      24             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      25             : #include <com/sun/star/xml/sax/InputSource.hpp>
      26             : #include <com/sun/star/xml/sax/Parser.hpp>
      27             : #include <com/sun/star/xml/sax/SAXParseException.hpp>
      28             : #include <com/sun/star/beans/PropertyValue.hpp>
      29             : #include <com/sun/star/presentation/EffectPresetClass.hpp>
      30             : #include <com/sun/star/beans/NamedValue.hpp>
      31             : #include <unotools/streamwrap.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <comphelper/string.hxx>
      34             : #include <unotools/pathoptions.hxx>
      35             : #include <tools/stream.hxx>
      36             : 
      37             : #include <tools/debug.hxx>
      38             : #include <rtl/uri.hxx>
      39             : #include <rtl/strbuf.hxx>
      40             : #include <vcl/svapp.hxx>
      41             : #include <osl/mutex.hxx>
      42             : #include <unotools/ucbstreamhelper.hxx>
      43             : #include <CustomAnimationPreset.hxx>
      44             : 
      45             : #include <algorithm>
      46             : 
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::uno;
      49             : using namespace ::com::sun::star::animations;
      50             : using namespace ::com::sun::star::presentation;
      51             : 
      52             : using ::rtl::OUString;
      53             : using ::com::sun::star::io::XInputStream;
      54             : using ::com::sun::star::lang::XMultiServiceFactory;
      55             : using ::com::sun::star::container::XNameAccess;
      56             : using ::com::sun::star::beans::PropertyValue;
      57             : using ::com::sun::star::util::XCloneable;
      58             : using ::com::sun::star::beans::NamedValue;
      59             : 
      60             : namespace sd {
      61             : 
      62           7 : static Reference< XNameAccess > getNodeAccess( const Reference< XMultiServiceFactory >& xConfigProvider, const OUString& rNodePath )
      63             : {
      64           7 :     Reference< XNameAccess > xConfigAccess;
      65             : 
      66             :     try
      67             :     {
      68           7 :         Sequence< Any > aArgs( 1 );
      69           7 :         PropertyValue   aPropValue;
      70           7 :         aPropValue.Name  = "nodepath";
      71           7 :         aPropValue.Value <<= rNodePath;
      72           7 :         aArgs[0] <<= aPropValue;
      73             : 
      74             :         xConfigAccess = Reference< XNameAccess >::query(
      75           7 :             xConfigProvider->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess" ,
      76           7 :                 aArgs ));
      77             :     }
      78           0 :     catch (const Exception&)
      79             :     {
      80             :         OSL_FAIL( "sd::getNodeAccess(), Exception caught!" );
      81             :     }
      82             : 
      83           7 :     return xConfigAccess;
      84             : }
      85             : 
      86           2 : void implImportLabels( const Reference< XMultiServiceFactory >& xConfigProvider, const OUString& rNodePath, UStringMap& rStringMap )
      87             : {
      88             :     try
      89             :     {
      90           2 :         Reference< XNameAccess > xConfigAccess( getNodeAccess( xConfigProvider, rNodePath ) );
      91           2 :         if( xConfigAccess.is() )
      92             :         {
      93           2 :             OUString aLabel( "Label" );
      94           2 :             Reference< XNameAccess > xNameAccess;
      95           2 :             Sequence< OUString > aNames( xConfigAccess->getElementNames() );
      96           2 :             const OUString* p = aNames.getConstArray();
      97           2 :             sal_Int32 n = aNames.getLength();
      98         262 :             while(n--)
      99             :             {
     100         258 :                 xConfigAccess->getByName( *p ) >>= xNameAccess;
     101         258 :                 if( xNameAccess.is() )
     102             :                 {
     103         258 :                     OUString aUIName;
     104         258 :                     xNameAccess->getByName( aLabel ) >>= aUIName;
     105         258 :                     if( !aUIName.isEmpty() )
     106             :                     {
     107         258 :                         rStringMap[ *p ] = aUIName;
     108         258 :                     }
     109             :                 }
     110             : 
     111         258 :                 p++;
     112           2 :             }
     113           2 :         }
     114             :     }
     115           0 :     catch (const lang::WrappedTargetException&)
     116             :     {
     117             :         OSL_FAIL( "sd::implImportLabels(), WrappedTargetException caught!" );
     118             :     }
     119           0 :     catch (const Exception&)
     120             :     {
     121             :         OSL_FAIL( "sd::implImportLabels(), Exception caught!" );
     122             :     }
     123           2 : }
     124             : 
     125           0 : CustomAnimationPreset::CustomAnimationPreset( CustomAnimationEffectPtr pEffect )
     126             : {
     127           0 :     maPresetId = pEffect->getPresetId();
     128           0 :     maProperty = pEffect->getProperty();
     129           0 :     mnPresetClass = pEffect->getPresetClass();
     130             : 
     131           0 :     add( pEffect );
     132             : 
     133           0 :     mfDuration = pEffect->getDuration();
     134           0 :     maDefaultSubTyp = pEffect->getPresetSubType();
     135             : 
     136           0 :     mbIsTextOnly = false;
     137             : 
     138           0 :     Sequence< NamedValue > aUserData( pEffect->getNode()->getUserData() );
     139           0 :     sal_Int32 nLength = aUserData.getLength();
     140           0 :     const NamedValue* p = aUserData.getConstArray();
     141             : 
     142           0 :     while( nLength-- )
     143             :     {
     144           0 :         if ( p->Name == "text-only" )
     145             :         {
     146           0 :             mbIsTextOnly = true;
     147           0 :             break;
     148             :         }
     149           0 :         p++;
     150           0 :     }
     151             : 
     152           0 : }
     153             : 
     154           0 : void CustomAnimationPreset::add( CustomAnimationEffectPtr pEffect )
     155             : {
     156           0 :     maSubTypes[ pEffect->getPresetSubType() ] = pEffect;
     157           0 : }
     158             : 
     159           0 : UStringList CustomAnimationPreset::getSubTypes()
     160             : {
     161           0 :     UStringList aSubTypes;
     162             : 
     163           0 :     if( maSubTypes.size() > 1 )
     164             :     {
     165           0 :         EffectsSubTypeMap::iterator aIter( maSubTypes.begin() );
     166           0 :         const EffectsSubTypeMap::iterator aEnd( maSubTypes.end() );
     167           0 :         while( aIter != aEnd )
     168           0 :             aSubTypes.push_back( (*aIter++).first );
     169             :     }
     170             : 
     171           0 :     return aSubTypes;
     172             : }
     173             : 
     174           0 : Reference< XAnimationNode > CustomAnimationPreset::create( const rtl::OUString& rstrSubType )
     175             : {
     176             :     try
     177             :     {
     178           0 :         OUString strSubType( rstrSubType );
     179           0 :         if( strSubType.isEmpty() )
     180           0 :             strSubType = maDefaultSubTyp;
     181             : 
     182           0 :         CustomAnimationEffectPtr pEffect = maSubTypes[strSubType];
     183           0 :         if( pEffect.get() )
     184             :         {
     185           0 :             Reference< XCloneable > xCloneable( pEffect->getNode(), UNO_QUERY_THROW );
     186           0 :             Reference< XAnimationNode > xNode( xCloneable->createClone(), UNO_QUERY_THROW );
     187           0 :             return xNode;
     188           0 :         }
     189             :     }
     190           0 :     catch (const Exception&)
     191             :     {
     192             :         OSL_FAIL( "sd::CustomAnimationPresets::create(), exception caught!" );
     193             :     }
     194             : 
     195           0 :     Reference< XAnimationNode > xNode;
     196           0 :     return xNode;
     197             : }
     198             : 
     199           0 : UStringList CustomAnimationPreset::getProperties() const
     200             : {
     201           0 :     String aProperties( maProperty );
     202           0 :     sal_uInt16 nTokens = comphelper::string::getTokenCount(aProperties, ';');
     203             :     sal_uInt16 nToken;
     204           0 :     UStringList aPropertyList;
     205           0 :     for( nToken = 0; nToken < nTokens; nToken++ )
     206           0 :         aPropertyList.push_back( aProperties.GetToken( nToken ) );
     207             : 
     208           0 :     return aPropertyList;
     209             : 
     210             : }
     211             : 
     212           0 : bool CustomAnimationPreset::hasProperty( const OUString& rProperty )const
     213             : {
     214           0 :     String aProperties( maProperty );
     215           0 :     String aProperty( rProperty );
     216           0 :     sal_uInt16 nTokens = comphelper::string::getTokenCount(aProperties, ';');
     217             :     sal_uInt16 nToken;
     218           0 :     for( nToken = 0; nToken < nTokens; nToken++ )
     219             :     {
     220           0 :         if( aProperties.GetToken( nToken ) == aProperty )
     221           0 :             return true;
     222             :     }
     223             : 
     224           0 :     return false;
     225             : }
     226             : 
     227           1 : CustomAnimationPresets::CustomAnimationPresets()
     228             : {
     229           1 : }
     230             : 
     231           0 : CustomAnimationPresets::~CustomAnimationPresets()
     232             : {
     233           0 : }
     234             : 
     235           1 : void CustomAnimationPresets::init()
     236             : {
     237           1 :     importResources();
     238           1 : }
     239             : 
     240           1 : Reference< XAnimationNode > implImportEffects( const Reference< XMultiServiceFactory >& xServiceFactory, const OUString& rPath )
     241             : {
     242           1 :     Reference< XAnimationNode > xRootNode;
     243             : 
     244             :     try
     245             :     {
     246             :         // create stream
     247           1 :         SvStream*   pIStm = ::utl::UcbStreamHelper::CreateStream( rPath, STREAM_READ );
     248           1 :         Reference<XInputStream> xInputStream( new utl::OInputStreamWrapper( pIStm, sal_True ) );
     249             : 
     250             :         // prepare ParserInputSrouce
     251           1 :         xml::sax::InputSource aParserInput;
     252           1 :         aParserInput.sSystemId = rPath;
     253           1 :         aParserInput.aInputStream = xInputStream;
     254             : 
     255             :         // get parser
     256           1 :         Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( comphelper::getComponentContext(xServiceFactory) );
     257             : 
     258             :         // get filter
     259           1 :         Reference< xml::sax::XDocumentHandler > xFilter( xServiceFactory->createInstance("com.sun.star.comp.Xmloff.AnimationsImport" ), UNO_QUERY );
     260             : 
     261             :         DBG_ASSERT( xFilter.is(), "Can't instantiate filter component." );
     262           1 :         if( !xFilter.is() )
     263             :             return xRootNode;
     264             : 
     265             :         // connect parser and filter
     266           1 :         xParser->setDocumentHandler( xFilter );
     267             : 
     268             :         // finally, parser the stream
     269           1 :         xParser->parseStream( aParserInput );
     270             : 
     271           0 :         Reference< XAnimationNodeSupplier > xAnimationNodeSupplier( xFilter, UNO_QUERY );
     272           0 :         if( xAnimationNodeSupplier.is() )
     273           0 :             xRootNode = xAnimationNodeSupplier->getAnimationNode();
     274             :     }
     275           0 :     catch (const xml::sax::SAXParseException&)
     276             :     {
     277             :         OSL_FAIL( "sd::implImportEffects(), SAXParseException caught!" );
     278             :     }
     279           0 :     catch (const xml::sax::SAXException&)
     280             :     {
     281             :         OSL_FAIL( "sd::implImportEffects(), SAXException caught!" );
     282             :     }
     283           1 :     catch (const io::IOException&)
     284             :     {
     285             :         OSL_FAIL( "sd::implImportEffects(), IOException caught!" );
     286             :     }
     287           0 :     catch (const Exception&)
     288             :     {
     289             :         OSL_FAIL( "sd::importEffects(), Exception caught!" );
     290             :     }
     291             : 
     292           1 :     return xRootNode;
     293             : }
     294             : 
     295             : #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
     296             : 
     297           1 : void CustomAnimationPresets::importEffects()
     298             : {
     299             :     try
     300             :     {
     301             :         uno::Reference< uno::XComponentContext > xContext(
     302           1 :             comphelper::getProcessComponentContext() );
     303             :         Reference< XMultiServiceFactory > xServiceFactory(
     304           1 :             xContext->getServiceManager(), UNO_QUERY_THROW );
     305             : 
     306             :         uno::Reference< util::XMacroExpander > xMacroExpander(
     307           1 :             xContext->getValueByName("/singletons/com.sun.star.util.theMacroExpander"),
     308           1 :             UNO_QUERY );
     309             : 
     310             :         Reference< XMultiServiceFactory > xConfigProvider =
     311           1 :             configuration::theDefaultProvider::get( xContext );
     312             : 
     313             :         // read path to transition effects files from config
     314             :         Any propValue = uno::makeAny(
     315             :             beans::PropertyValue(
     316             :                 "nodepath", -1,
     317             :                 uno::makeAny( OUString( "/org.openoffice.Office.Impress/Misc" )),
     318           1 :                 beans::PropertyState_DIRECT_VALUE ) );
     319             : 
     320             :         Reference<container::XNameAccess> xNameAccess(
     321           1 :             xConfigProvider->createInstanceWithArguments(
     322             :                 "com.sun.star.configuration.ConfigurationAccess",
     323           1 :                 Sequence<Any>( &propValue, 1 ) ), UNO_QUERY_THROW );
     324           1 :         uno::Sequence< rtl::OUString > aFiles;
     325           1 :         xNameAccess->getByName( "EffectFiles" ) >>= aFiles;
     326             : 
     327           2 :         for( sal_Int32 i=0; i<aFiles.getLength(); ++i )
     328             :         {
     329           1 :             rtl::OUString aURL = aFiles[i];
     330           1 :             if( aURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL )) == 0 )
     331             :             {
     332             :                 // cut protocol
     333           1 :                 rtl::OUString aMacro( aURL.copy( sizeof ( EXPAND_PROTOCOL ) -1 ) );
     334             :                 // decode uric class chars
     335           1 :                 aMacro = rtl::Uri::decode( aMacro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
     336             :                 // expand macro string
     337           1 :                 aURL = xMacroExpander->expandMacros( aMacro );
     338             :             }
     339             : 
     340           1 :             mxRootNode = implImportEffects( xServiceFactory, aURL );
     341             : 
     342           1 :             if( mxRootNode.is() )
     343             :             {
     344           0 :                 Reference< XTimeContainer > xRootContainer( mxRootNode, UNO_QUERY_THROW );
     345           0 :                 EffectSequenceHelper aSequence( xRootContainer );
     346             : 
     347           0 :                 EffectSequence::iterator aIter( aSequence.getBegin() );
     348           0 :                 const EffectSequence::iterator aEnd( aSequence.getEnd() );
     349             : 
     350           0 :                 while( aIter != aEnd )
     351             :                 {
     352           0 :                     CustomAnimationEffectPtr pEffect = (*aIter);
     353             : 
     354           0 :                     const OUString aPresetId( pEffect->getPresetId() );
     355           0 :                     CustomAnimationPresetPtr pDescriptor = getEffectDescriptor( aPresetId );
     356           0 :                     if( pDescriptor.get() )
     357           0 :                         pDescriptor->add( pEffect );
     358             :                     else
     359             :                     {
     360           0 :                         pDescriptor.reset( new CustomAnimationPreset( pEffect ) );
     361           0 :                         pDescriptor->maLabel = getUINameForPresetId( pEffect->getPresetId() );
     362           0 :                         maEffectDiscriptorMap[aPresetId] = pDescriptor;
     363             :                     }
     364             : 
     365           0 :                     ++aIter;
     366           0 :                 }
     367             :             }
     368           2 :         }
     369             :     }
     370           0 :     catch (const xml::sax::SAXParseException&)
     371             :     {
     372             :         OSL_FAIL( "sd::CustomAnimationPresets::importEffects(), SAXParseException caught!" );
     373             :     }
     374           0 :     catch (const xml::sax::SAXException&)
     375             :     {
     376             :         OSL_FAIL( "sd::CustomAnimationPresets::importEffects(), SAXException caught!" );
     377             :     }
     378           0 :     catch (const io::IOException&)
     379             :     {
     380             :         OSL_FAIL( "sd::CustomAnimationPresets::importEffects(), IOException caught!" );
     381             :     }
     382           0 :     catch (const Exception&)
     383             :     {
     384             :         OSL_FAIL( "sd::CustomAnimationPresets::importEffects(), Exception caught!" );
     385             :     }
     386           1 : }
     387             : 
     388           1 : void CustomAnimationPresets::importResources()
     389             : {
     390             :     try
     391             :     {
     392             :         // Get service factory
     393           1 :         Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
     394             : 
     395             :         Reference< XMultiServiceFactory > xConfigProvider =
     396           1 :              configuration::theDefaultProvider::get( xContext );
     397             : 
     398           1 :         const OUString aPropertyPath("/org.openoffice.Office.UI.Effects/UserInterface/Properties" );
     399           1 :         implImportLabels( xConfigProvider, aPropertyPath, maPropertyNameMap );
     400             : 
     401           1 :         const OUString aEffectsPath( "/org.openoffice.Office.UI.Effects/UserInterface/Effects" );
     402           1 :         implImportLabels( xConfigProvider, aEffectsPath, maEffectNameMap );
     403             : 
     404           1 :         importEffects();
     405             : 
     406           1 :         const OUString aEntrancePath( "/org.openoffice.Office.UI.Effects/Presets/Entrance" );
     407           1 :         importPresets( xConfigProvider, aEntrancePath, maEntrancePresets );
     408             : 
     409           1 :         const OUString aEmphasisPath( "/org.openoffice.Office.UI.Effects/Presets/Emphasis" );
     410           1 :         importPresets( xConfigProvider, aEmphasisPath, maEmphasisPresets );
     411             : 
     412           1 :         const OUString aExitPath( "/org.openoffice.Office.UI.Effects/Presets/Exit" );
     413           1 :         importPresets( xConfigProvider, aExitPath, maExitPresets );
     414             : 
     415           1 :         const OUString aMotionPathsPath( "/org.openoffice.Office.UI.Effects/Presets/MotionPaths" );
     416           1 :         importPresets( xConfigProvider, aMotionPathsPath, maMotionPathsPresets );
     417             : 
     418           1 :         const OUString aMiscPath( "/org.openoffice.Office.UI.Effects/Presets/Misc" );
     419           1 :         importPresets( xConfigProvider, aMiscPath, maMiscPresets );
     420             :     }
     421           0 :     catch (const lang::WrappedTargetException&)
     422             :     {
     423             :         OSL_FAIL( "sd::CustomAnimationPresets::importResources(), WrappedTargetException caught!" );
     424             :     }
     425           0 :     catch (const Exception&)
     426             :     {
     427             :         OSL_FAIL( "sd::CustomAnimationPresets::importResources(), Exception caught!" );
     428             :     }
     429           1 : }
     430             : 
     431           5 : void CustomAnimationPresets::importPresets( const Reference< XMultiServiceFactory >& xConfigProvider, const OUString& rNodePath, PresetCategoryList& rPresetMap  )
     432             : {
     433             : #ifdef DEBUG
     434             :     String aMissedPresetIds;
     435             : #endif
     436             : 
     437             :     try
     438             :     {
     439           5 :         Reference< XNameAccess > xTypeAccess( getNodeAccess( xConfigProvider, rNodePath ) );
     440           5 :         if( xTypeAccess.is() )
     441             :         {
     442           5 :             Reference< XNameAccess > xCategoryAccess;
     443           5 :             const OUString aEffectsName( "Effects" );
     444           5 :             const OUString aLabelName( "Label" );
     445             : 
     446           5 :             Sequence< OUString > aNames( xTypeAccess->getElementNames() );
     447           5 :             const OUString* p = aNames.getConstArray();
     448           5 :             sal_Int32 n = aNames.getLength();
     449          26 :             while(n--)
     450             :             {
     451          16 :                 xTypeAccess->getByName( *p ) >>= xCategoryAccess;
     452             : 
     453          16 :                 if( xCategoryAccess.is() && xCategoryAccess->hasByName( aLabelName ) && xCategoryAccess->hasByName( aEffectsName ) )
     454             :                 {
     455          16 :                     OUString aLabel;
     456          16 :                     xCategoryAccess->getByName( aLabelName ) >>= aLabel;
     457             : 
     458          16 :                     Sequence< OUString > aEffects;
     459          16 :                     xCategoryAccess->getByName( aEffectsName ) >>= aEffects;
     460             : 
     461          16 :                     EffectDescriptorList aEffectsList;
     462             : 
     463          16 :                     const OUString* pEffectNames = aEffects.getConstArray();
     464          16 :                     sal_Int32 nEffectCount = aEffects.getLength();
     465         232 :                     while( nEffectCount-- )
     466             :                     {
     467         200 :                         CustomAnimationPresetPtr pEffect = getEffectDescriptor( *pEffectNames );
     468         200 :                         if( pEffect.get() )
     469             :                         {
     470           0 :                             aEffectsList.push_back( pEffect );
     471             :                         }
     472             : #ifdef DEBUG
     473             :                         else
     474             :                         {
     475             :                             aMissedPresetIds += String(*pEffectNames);
     476             :                             aMissedPresetIds += String( RTL_CONSTASCII_USTRINGPARAM("\n") );
     477             :                         }
     478             : #endif
     479         200 :                         pEffectNames++;
     480         200 :                     }
     481          16 :                     rPresetMap.push_back( PresetCategoryPtr( new PresetCategory( aLabel, aEffectsList ) ) );
     482             :                 }
     483             : 
     484          16 :                 p++;
     485           5 :             }
     486           5 :         }
     487             :     }
     488           0 :     catch (const Exception&)
     489             :     {
     490             :         OSL_FAIL( "sd::CustomAnimationPresets::importPresets(), Exception caught!" );
     491             :     }
     492             : 
     493             : #ifdef DEBUG
     494             :     if( aMissedPresetIds.Len() )
     495             :     {
     496             :         rtl::OStringBuffer aTmp(RTL_CONSTASCII_STRINGPARAM("sd::CustomAnimationPresets::importPresets(), invalid preset id!\n"));
     497             :         aTmp.append(rtl::OUStringToOString(aMissedPresetIds,
     498             :             RTL_TEXTENCODING_ASCII_US));
     499             :         OSL_FAIL(aTmp.getStr());
     500             :     }
     501             : #endif
     502           5 : }
     503             : 
     504         233 : CustomAnimationPresetPtr CustomAnimationPresets::getEffectDescriptor( const rtl::OUString& rPresetId ) const
     505             : {
     506         233 :     EffectDescriptorMap::const_iterator aIter( maEffectDiscriptorMap.find( rPresetId ) );
     507             : 
     508         233 :     if( aIter != maEffectDiscriptorMap.end() )
     509             :     {
     510           0 :         return (*aIter).second;
     511             :     }
     512             :     else
     513             :     {
     514         233 :         return CustomAnimationPresetPtr((CustomAnimationPreset*)0);
     515             :     }
     516             : }
     517             : 
     518           0 : const rtl::OUString& CustomAnimationPresets::getUINameForPresetId( const rtl::OUString& rPresetId ) const
     519             : {
     520           0 :     return translateName( rPresetId, maEffectNameMap );
     521             : }
     522             : 
     523           0 : const rtl::OUString& CustomAnimationPresets::getUINameForProperty( const rtl::OUString& rPresetId ) const
     524             : {
     525           0 :     return translateName( rPresetId, maPropertyNameMap );
     526             : }
     527             : 
     528           0 : const rtl::OUString& CustomAnimationPresets::translateName( const rtl::OUString& rId, const UStringMap& rNameMap ) const
     529             : {
     530           0 :     UStringMap::const_iterator aIter( rNameMap.find( rId ) );
     531             : 
     532           0 :     if( aIter != rNameMap.end() )
     533             :     {
     534           0 :         return (*aIter).second;
     535             :     }
     536             :     else
     537             :     {
     538           0 :         return rId;
     539             :     }
     540             : }
     541           0 : void CustomAnimationPresets::changePresetSubType( CustomAnimationEffectPtr pEffect, const rtl::OUString& rPresetSubType ) const
     542             : {
     543           0 :     if( pEffect.get() && pEffect->getPresetSubType() != rPresetSubType )
     544             :     {
     545           0 :         CustomAnimationPresetPtr pDescriptor( getEffectDescriptor( pEffect->getPresetId() ) );
     546             : 
     547           0 :         if( pDescriptor.get() )
     548             :         {
     549           0 :             Reference< XAnimationNode > xNewNode( pDescriptor->create( rPresetSubType ) );
     550           0 :             if( xNewNode.is() )
     551           0 :                 pEffect->replaceNode( xNewNode );
     552           0 :         }
     553             :     }
     554           0 : }
     555             : 
     556             : CustomAnimationPresets* CustomAnimationPresets::mpCustomAnimationPresets = 0;
     557             : 
     558          33 : const CustomAnimationPresets& CustomAnimationPresets::getCustomAnimationPresets()
     559             : {
     560          33 :     if( !mpCustomAnimationPresets )
     561             :     {
     562           1 :         SolarMutexGuard aGuard;
     563             : 
     564           1 :         if( !mpCustomAnimationPresets )
     565             :         {
     566           1 :             mpCustomAnimationPresets = new sd::CustomAnimationPresets();
     567           1 :             mpCustomAnimationPresets->init();
     568           1 :         }
     569             :     }
     570             : 
     571          33 :     return *mpCustomAnimationPresets;
     572             : }
     573             : 
     574           0 : Reference< XAnimationNode > CustomAnimationPresets::getRandomPreset( sal_Int16 nPresetClass ) const
     575             : {
     576           0 :     Reference< XAnimationNode > xNode;
     577             : 
     578           0 :     const PresetCategoryList* pCategoryList = 0;
     579           0 :     switch( nPresetClass )
     580             :     {
     581           0 :     case EffectPresetClass::ENTRANCE:   pCategoryList = &maEntrancePresets; break;
     582           0 :     case EffectPresetClass::EXIT:       pCategoryList = &maExitPresets; break;
     583           0 :     case EffectPresetClass::EMPHASIS:   pCategoryList = &maEmphasisPresets; break;
     584           0 :     case EffectPresetClass::MOTIONPATH: pCategoryList = &maMotionPathsPresets; break;
     585             :     default:
     586           0 :         pCategoryList = 0;
     587             :     }
     588             : 
     589           0 :     if( pCategoryList && pCategoryList->size() )
     590             :     {
     591           0 :         sal_Int32 nCategory = (rand() * pCategoryList->size() / RAND_MAX);
     592             : 
     593           0 :         PresetCategoryPtr pCategory = (*pCategoryList)[nCategory];
     594           0 :         if( pCategory.get() && !pCategory->maEffects.empty() )
     595             :         {
     596           0 :             sal_Int32 nDescriptor = (rand() * pCategory->maEffects.size() / RAND_MAX);
     597           0 :             CustomAnimationPresetPtr pPreset = pCategory->maEffects[nDescriptor];
     598           0 :             if( pPreset.get() )
     599             :             {
     600           0 :                 UStringList aSubTypes = pPreset->getSubTypes();
     601             : 
     602           0 :                 OUString aSubType;
     603           0 :                 if( !aSubTypes.empty() )
     604             :                 {
     605           0 :                     sal_Int32 nSubType = (rand() * aSubTypes.size() / RAND_MAX);
     606           0 :                     aSubType = aSubTypes[nSubType];
     607             :                 }
     608           0 :                 xNode = pPreset->create( aSubType );
     609           0 :             }
     610           0 :         }
     611             :     }
     612             : 
     613           0 :     return xNode;
     614             : }
     615             : 
     616             : 
     617             : }
     618             : 
     619             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10