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