1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TransitionPreset.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/animations/XTimeContainer.hpp>
34 #include <com/sun/star/animations/XTransitionFilter.hpp>
35 #include <com/sun/star/container/XEnumerationAccess.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/beans/NamedValue.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/util/XMacroExpander.hpp>
40 #include <com/sun/star/animations/AnimationNodeType.hpp>
41 #include <vcl/svapp.hxx>
42 #include <vos/mutex.hxx>
43 #include <tools/urlobj.hxx>
44 #include <unotools/streamwrap.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <svtools/pathoptions.hxx>
47 #include <tools/stream.hxx>
49 #include <rtl/uri.hxx>
50 #include <tools/debug.hxx>
52 #ifndef _SD_CUSTOMANIMATIONPRESET_HXX
53 #include <TransitionPreset.hxx>
55 #include <unotools/ucbstreamhelper.hxx>
61 using namespace ::vos
;
62 using namespace ::com::sun::star
;
63 using namespace ::com::sun::star::animations
;
65 using ::rtl::OUString
;
66 using ::com::sun::star::uno::UNO_QUERY
;
67 using ::com::sun::star::uno::UNO_QUERY_THROW
;
68 using ::com::sun::star::uno::Any
;
69 using ::com::sun::star::uno::Sequence
;
70 using ::com::sun::star::uno::Reference
;
71 using ::com::sun::star::uno::Exception
;
72 using ::com::sun::star::lang::XMultiServiceFactory
;
73 using ::com::sun::star::container::XEnumerationAccess
;
74 using ::com::sun::star::container::XEnumeration
;
75 using ::com::sun::star::beans::NamedValue
;
79 extern Reference
< XAnimationNode
> implImportEffects( const Reference
< XMultiServiceFactory
>& xConfigProvider
, const OUString
& rPath
);
80 extern void implImportLabels( const Reference
< XMultiServiceFactory
>& xConfigProvider
, const OUString
& rNodePath
, UStringMap
& rStringMap
);
82 TransitionPreset::TransitionPreset( const ::com::sun::star::uno::Reference
< ::com::sun::star::animations::XAnimationNode
>& xNode
)
84 // first locate preset id
85 Sequence
< NamedValue
> aUserData( xNode
->getUserData() );
86 sal_Int32 nLength
= aUserData
.getLength();
87 const NamedValue
* p
= aUserData
.getConstArray();
90 if( p
->Name
.equalsAscii( "preset-id" ) )
92 p
->Value
>>= maPresetId
;
97 // second, locate transition filter element
98 Reference
< XEnumerationAccess
> xEnumerationAccess( xNode
, UNO_QUERY_THROW
);
99 Reference
< XEnumeration
> xEnumeration( xEnumerationAccess
->createEnumeration(), UNO_QUERY_THROW
);
100 Reference
< XTransitionFilter
> xTransition( xEnumeration
->nextElement(), UNO_QUERY_THROW
);
102 mnTransition
= xTransition
->getTransition();
103 mnSubtype
= xTransition
->getSubtype();
104 mbDirection
= xTransition
->getDirection();
105 mnFadeColor
= xTransition
->getFadeColor();
108 bool TransitionPreset::importTransitionsFile( TransitionPresetList
& rList
,
109 Reference
< XMultiServiceFactory
>& xServiceFactory
,
110 UStringMap
& rTransitionNameMape
,
113 // import transition presets
114 Reference
< XAnimationNode
> xAnimationNode
;
117 xAnimationNode
= implImportEffects( xServiceFactory
, aURL
);
118 Reference
< XEnumerationAccess
> xEnumerationAccess( xAnimationNode
, UNO_QUERY_THROW
);
119 Reference
< XEnumeration
> xEnumeration( xEnumerationAccess
->createEnumeration(), UNO_QUERY_THROW
);
121 while( xEnumeration
->hasMoreElements() )
123 Reference
< XAnimationNode
> xChildNode( xEnumeration
->nextElement(), UNO_QUERY_THROW
);
124 if( xChildNode
->getType() == AnimationNodeType::PAR
)
127 TransitionPresetPtr
pPreset( new TransitionPreset( xChildNode
) );
130 OUString
aPresetId( pPreset
->getPresetId() );
131 if( aPresetId
.getLength() )
133 UStringMap::const_iterator
aIter( rTransitionNameMape
.find( aPresetId
) );
134 if( aIter
!= rTransitionNameMape
.end() )
135 pPreset
->maUIName
= (*aIter
).second
;
138 rList
.push_back( pPreset
);
143 DBG_ERROR( "sd::TransitionPreset::importTransitionPresetList(), missformed xml configuration file, giving up!" );
147 } catch( Exception
& ) {
154 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
156 bool TransitionPreset::importTransitionPresetList( TransitionPresetList
& rList
)
162 // Get service factory
163 Reference
< XMultiServiceFactory
> xServiceFactory( comphelper::getProcessServiceFactory() );
164 DBG_ASSERT( xServiceFactory
.is(), "sd::CustomAnimationPresets::import(), got no service manager" );
165 if( !xServiceFactory
.is() )
168 uno::Reference
< beans::XPropertySet
> xProps( xServiceFactory
, UNO_QUERY
);
169 uno::Reference
< uno::XComponentContext
> xContext
;
170 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext
;
172 uno::Reference
< util::XMacroExpander
> xMacroExpander
;
174 xMacroExpander
.set( xContext
->getValueByName(
175 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander"))),
179 Reference
< XMultiServiceFactory
> xConfigProvider(
180 xServiceFactory
->createInstance(
181 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ))),
184 UStringMap aTransitionNameMape
;
185 const OUString
aTransitionPath( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Effects/UserInterface/Transitions" ) );
186 implImportLabels( xConfigProvider
, aTransitionPath
, aTransitionNameMape
);
188 // read path to transition effects files from config
189 Any propValue
= uno::makeAny(
190 beans::PropertyValue(
191 OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath")), -1,
192 uno::makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Impress/Misc"))),
193 beans::PropertyState_DIRECT_VALUE
) );
195 Reference
<container::XNameAccess
> xNameAccess(
196 xConfigProvider
->createInstanceWithArguments(
197 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationAccess")),
198 Sequence
<Any
>( &propValue
, 1 ) ), UNO_QUERY_THROW
);
199 uno::Sequence
< rtl::OUString
> aFiles
;
200 xNameAccess
->getByName(
201 OUString( RTL_CONSTASCII_USTRINGPARAM("TransitionFiles"))) >>= aFiles
;
203 for( sal_Int32 i
=0; i
<aFiles
.getLength(); ++i
)
205 rtl::OUString aURL
= aFiles
[i
];
206 if( aURL
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL
)) == 0 )
209 rtl::OUString
aMacro( aURL
.copy( sizeof ( EXPAND_PROTOCOL
) -1 ) );
210 // decode uric class chars
211 aMacro
= rtl::Uri::decode( aMacro
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
212 // expand macro string
213 aURL
= xMacroExpander
->expandMacros( aMacro
);
216 bRet
|= importTransitionsFile( rList
,
224 catch( Exception
& e
)
227 DBG_ERROR( "sd::TransitionPreset::importResources(), Exception cought!" );
233 TransitionPresetList
* TransitionPreset::mpTransitionPresetList
= 0;
235 const TransitionPresetList
& TransitionPreset::getTransitionPresetList()
237 if( !mpTransitionPresetList
)
239 OGuard
aGuard( Application::GetSolarMutex() );
240 if( !mpTransitionPresetList
)
242 mpTransitionPresetList
= new sd::TransitionPresetList();
243 sd::TransitionPreset::importTransitionPresetList( *mpTransitionPresetList
);
247 return *mpTransitionPresetList
;
250 void TransitionPreset::apply( SdPage
* pSlide
) const
254 pSlide
->setTransitionType( mnTransition
);
255 pSlide
->setTransitionSubtype( mnSubtype
);
256 pSlide
->setTransitionDirection( mbDirection
);
257 pSlide
->setTransitionFadeColor( mnFadeColor
);