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