1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 #include <com/sun/star/animations/XTimeContainer.hpp>
31 #include <com/sun/star/animations/XTransitionFilter.hpp>
32 #include <com/sun/star/container/XEnumerationAccess.hpp>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/beans/NamedValue.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/util/XMacroExpander.hpp>
37 #include <com/sun/star/animations/AnimationNodeType.hpp>
38 #include <vcl/svapp.hxx>
39 #include <vos/mutex.hxx>
40 #include <tools/urlobj.hxx>
41 #include <unotools/streamwrap.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <unotools/pathoptions.hxx>
44 #include <tools/stream.hxx>
46 #include <rtl/uri.hxx>
47 #include <tools/debug.hxx>
49 #ifndef _SD_CUSTOMANIMATIONPRESET_HXX
50 #include <TransitionPreset.hxx>
52 #include <unotools/ucbstreamhelper.hxx>
58 using namespace ::vos
;
59 using namespace ::com::sun::star
;
60 using namespace ::com::sun::star::animations
;
62 using ::rtl::OUString
;
63 using ::com::sun::star::uno::UNO_QUERY
;
64 using ::com::sun::star::uno::UNO_QUERY_THROW
;
65 using ::com::sun::star::uno::Any
;
66 using ::com::sun::star::uno::Sequence
;
67 using ::com::sun::star::uno::Reference
;
68 using ::com::sun::star::uno::Exception
;
69 using ::com::sun::star::lang::XMultiServiceFactory
;
70 using ::com::sun::star::container::XEnumerationAccess
;
71 using ::com::sun::star::container::XEnumeration
;
72 using ::com::sun::star::beans::NamedValue
;
76 extern Reference
< XAnimationNode
> implImportEffects( const Reference
< XMultiServiceFactory
>& xConfigProvider
, const OUString
& rPath
);
77 extern void implImportLabels( const Reference
< XMultiServiceFactory
>& xConfigProvider
, const OUString
& rNodePath
, UStringMap
& rStringMap
);
79 TransitionPreset::TransitionPreset( const ::com::sun::star::uno::Reference
< ::com::sun::star::animations::XAnimationNode
>& xNode
)
81 // first locate preset id
82 Sequence
< NamedValue
> aUserData( xNode
->getUserData() );
83 sal_Int32 nLength
= aUserData
.getLength();
84 const NamedValue
* p
= aUserData
.getConstArray();
87 if( p
->Name
.equalsAscii( "preset-id" ) )
89 p
->Value
>>= maPresetId
;
94 // second, locate transition filter element
95 Reference
< XEnumerationAccess
> xEnumerationAccess( xNode
, UNO_QUERY_THROW
);
96 Reference
< XEnumeration
> xEnumeration( xEnumerationAccess
->createEnumeration(), UNO_QUERY_THROW
);
97 Reference
< XTransitionFilter
> xTransition( xEnumeration
->nextElement(), UNO_QUERY_THROW
);
99 mnTransition
= xTransition
->getTransition();
100 mnSubtype
= xTransition
->getSubtype();
101 mbDirection
= xTransition
->getDirection();
102 mnFadeColor
= xTransition
->getFadeColor();
105 bool TransitionPreset::importTransitionsFile( TransitionPresetList
& rList
,
106 Reference
< XMultiServiceFactory
>& xServiceFactory
,
107 UStringMap
& rTransitionNameMape
,
110 // import transition presets
111 Reference
< XAnimationNode
> xAnimationNode
;
114 xAnimationNode
= implImportEffects( xServiceFactory
, aURL
);
115 Reference
< XEnumerationAccess
> xEnumerationAccess( xAnimationNode
, UNO_QUERY_THROW
);
116 Reference
< XEnumeration
> xEnumeration( xEnumerationAccess
->createEnumeration(), UNO_QUERY_THROW
);
118 while( xEnumeration
->hasMoreElements() )
120 Reference
< XAnimationNode
> xChildNode( xEnumeration
->nextElement(), UNO_QUERY_THROW
);
121 if( xChildNode
->getType() == AnimationNodeType::PAR
)
124 TransitionPresetPtr
pPreset( new TransitionPreset( xChildNode
) );
127 OUString
aPresetId( pPreset
->getPresetId() );
128 if( aPresetId
.getLength() )
130 UStringMap::const_iterator
aIter( rTransitionNameMape
.find( aPresetId
) );
131 if( aIter
!= rTransitionNameMape
.end() )
132 pPreset
->maUIName
= (*aIter
).second
;
135 rList
.push_back( pPreset
);
140 DBG_ERROR( "sd::TransitionPreset::importTransitionPresetList(), missformed xml configuration file, giving up!" );
144 } catch( Exception
& ) {
151 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
153 bool TransitionPreset::importTransitionPresetList( TransitionPresetList
& rList
)
159 // Get service factory
160 Reference
< XMultiServiceFactory
> xServiceFactory( comphelper::getProcessServiceFactory() );
161 DBG_ASSERT( xServiceFactory
.is(), "sd::CustomAnimationPresets::import(), got no service manager" );
162 if( !xServiceFactory
.is() )
165 uno::Reference
< beans::XPropertySet
> xProps( xServiceFactory
, UNO_QUERY
);
166 uno::Reference
< uno::XComponentContext
> xContext
;
167 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext
;
169 uno::Reference
< util::XMacroExpander
> xMacroExpander
;
171 xMacroExpander
.set( xContext
->getValueByName(
172 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander"))),
176 Reference
< XMultiServiceFactory
> xConfigProvider(
177 xServiceFactory
->createInstance(
178 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ))),
181 UStringMap aTransitionNameMape
;
182 const OUString
aTransitionPath( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Effects/UserInterface/Transitions" ) );
183 implImportLabels( xConfigProvider
, aTransitionPath
, aTransitionNameMape
);
185 // read path to transition effects files from config
186 Any propValue
= uno::makeAny(
187 beans::PropertyValue(
188 OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath")), -1,
189 uno::makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Impress/Misc"))),
190 beans::PropertyState_DIRECT_VALUE
) );
192 Reference
<container::XNameAccess
> xNameAccess(
193 xConfigProvider
->createInstanceWithArguments(
194 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationAccess")),
195 Sequence
<Any
>( &propValue
, 1 ) ), UNO_QUERY_THROW
);
196 uno::Sequence
< rtl::OUString
> aFiles
;
197 xNameAccess
->getByName(
198 OUString( RTL_CONSTASCII_USTRINGPARAM("TransitionFiles"))) >>= aFiles
;
200 for( sal_Int32 i
=0; i
<aFiles
.getLength(); ++i
)
202 rtl::OUString aURL
= aFiles
[i
];
203 if( aURL
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL
)) == 0 )
206 rtl::OUString
aMacro( aURL
.copy( sizeof ( EXPAND_PROTOCOL
) -1 ) );
207 // decode uric class chars
208 aMacro
= rtl::Uri::decode( aMacro
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
209 // expand macro string
210 aURL
= xMacroExpander
->expandMacros( aMacro
);
213 bRet
|= importTransitionsFile( rList
,
221 catch( Exception
& e
)
224 DBG_ERROR( "sd::TransitionPreset::importResources(), Exception cought!" );
230 TransitionPresetList
* TransitionPreset::mpTransitionPresetList
= 0;
232 const TransitionPresetList
& TransitionPreset::getTransitionPresetList()
234 if( !mpTransitionPresetList
)
236 OGuard
aGuard( Application::GetSolarMutex() );
237 if( !mpTransitionPresetList
)
239 mpTransitionPresetList
= new sd::TransitionPresetList();
240 sd::TransitionPreset::importTransitionPresetList( *mpTransitionPresetList
);
244 return *mpTransitionPresetList
;
247 void TransitionPreset::apply( SdPage
* pSlide
) const
251 pSlide
->setTransitionType( mnTransition
);
252 pSlide
->setTransitionSubtype( mnSubtype
);
253 pSlide
->setTransitionDirection( mbDirection
);
254 pSlide
->setTransitionFadeColor( mnFadeColor
);