1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sd.hxx" 26cdf0e10cSrcweir #include <com/sun/star/animations/XTimeContainer.hpp> 27cdf0e10cSrcweir #include <com/sun/star/animations/XTransitionFilter.hpp> 28cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp> 29cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 30cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 32cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp> 33cdf0e10cSrcweir #include <com/sun/star/animations/AnimationNodeType.hpp> 34cdf0e10cSrcweir #include <vcl/svapp.hxx> 35cdf0e10cSrcweir #include <vos/mutex.hxx> 36cdf0e10cSrcweir #include <tools/urlobj.hxx> 37cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 38cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 39cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 40cdf0e10cSrcweir #include <tools/stream.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <rtl/uri.hxx> 43cdf0e10cSrcweir #include <tools/debug.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #ifndef _SD_CUSTOMANIMATIONPRESET_HXX 46cdf0e10cSrcweir #include <TransitionPreset.hxx> 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 49cdf0e10cSrcweir 50cdf0e10cSrcweir #include <algorithm> 51cdf0e10cSrcweir 52cdf0e10cSrcweir #include "sdpage.hxx" 53cdf0e10cSrcweir 54cdf0e10cSrcweir using namespace ::vos; 55cdf0e10cSrcweir using namespace ::com::sun::star; 56cdf0e10cSrcweir using namespace ::com::sun::star::animations; 57cdf0e10cSrcweir 58cdf0e10cSrcweir using ::rtl::OUString; 59cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 60cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 61cdf0e10cSrcweir using ::com::sun::star::uno::Any; 62cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 63cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 64cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 65cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 66cdf0e10cSrcweir using ::com::sun::star::container::XEnumerationAccess; 67cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration; 68cdf0e10cSrcweir using ::com::sun::star::beans::NamedValue; 69cdf0e10cSrcweir 70cdf0e10cSrcweir namespace sd { 71cdf0e10cSrcweir 72cdf0e10cSrcweir extern Reference< XAnimationNode > implImportEffects( const Reference< XMultiServiceFactory >& xConfigProvider, const OUString& rPath ); 73cdf0e10cSrcweir extern void implImportLabels( const Reference< XMultiServiceFactory >& xConfigProvider, const OUString& rNodePath, UStringMap& rStringMap ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir TransitionPreset::TransitionPreset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // first locate preset id 78cdf0e10cSrcweir Sequence< NamedValue > aUserData( xNode->getUserData() ); 79cdf0e10cSrcweir sal_Int32 nLength = aUserData.getLength(); 80cdf0e10cSrcweir const NamedValue* p = aUserData.getConstArray(); 81cdf0e10cSrcweir while( nLength-- ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir if( p->Name.equalsAscii( "preset-id" ) ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir p->Value >>= maPresetId; 86cdf0e10cSrcweir break; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir // second, locate transition filter element 91cdf0e10cSrcweir Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW ); 92cdf0e10cSrcweir Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW ); 93cdf0e10cSrcweir Reference< XTransitionFilter > xTransition( xEnumeration->nextElement(), UNO_QUERY_THROW ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir mnTransition = xTransition->getTransition(); 96cdf0e10cSrcweir mnSubtype = xTransition->getSubtype(); 97cdf0e10cSrcweir mbDirection = xTransition->getDirection(); 98cdf0e10cSrcweir mnFadeColor = xTransition->getFadeColor(); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir bool TransitionPreset::importTransitionsFile( TransitionPresetList& rList, 102cdf0e10cSrcweir Reference< XMultiServiceFactory >& xServiceFactory, 103cdf0e10cSrcweir UStringMap& rTransitionNameMape, 104cdf0e10cSrcweir String aURL ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir // import transition presets 107cdf0e10cSrcweir Reference< XAnimationNode > xAnimationNode; 108cdf0e10cSrcweir 109cdf0e10cSrcweir try { 110cdf0e10cSrcweir xAnimationNode = implImportEffects( xServiceFactory, aURL ); 111cdf0e10cSrcweir Reference< XEnumerationAccess > xEnumerationAccess( xAnimationNode, UNO_QUERY_THROW ); 112cdf0e10cSrcweir Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir while( xEnumeration->hasMoreElements() ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW ); 117cdf0e10cSrcweir if( xChildNode->getType() == AnimationNodeType::PAR ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir // create it 120cdf0e10cSrcweir TransitionPresetPtr pPreset( new TransitionPreset( xChildNode ) ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir // name it 123cdf0e10cSrcweir OUString aPresetId( pPreset->getPresetId() ); 124cdf0e10cSrcweir if( aPresetId.getLength() ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir UStringMap::const_iterator aIter( rTransitionNameMape.find( aPresetId ) ); 127cdf0e10cSrcweir if( aIter != rTransitionNameMape.end() ) 128cdf0e10cSrcweir pPreset->maUIName = (*aIter).second; 129cdf0e10cSrcweir 130cdf0e10cSrcweir // add it 131cdf0e10cSrcweir rList.push_back( pPreset ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else 135cdf0e10cSrcweir { 136cdf0e10cSrcweir DBG_ERROR( "sd::TransitionPreset::importTransitionPresetList(), missformed xml configuration file, giving up!" ); 137cdf0e10cSrcweir break; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } catch( Exception& ) { 141cdf0e10cSrcweir return false; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir return true; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir #define EXPAND_PROTOCOL "vnd.sun.star.expand:" 148cdf0e10cSrcweir 149cdf0e10cSrcweir bool TransitionPreset::importTransitionPresetList( TransitionPresetList& rList ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir bool bRet = false; 152cdf0e10cSrcweir 153cdf0e10cSrcweir try 154cdf0e10cSrcweir { 155cdf0e10cSrcweir // Get service factory 156cdf0e10cSrcweir Reference< XMultiServiceFactory > xServiceFactory( comphelper::getProcessServiceFactory() ); 157cdf0e10cSrcweir DBG_ASSERT( xServiceFactory.is(), "sd::CustomAnimationPresets::import(), got no service manager" ); 158cdf0e10cSrcweir if( !xServiceFactory.is() ) 159cdf0e10cSrcweir return false; 160cdf0e10cSrcweir 161cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xServiceFactory, UNO_QUERY ); 162cdf0e10cSrcweir uno::Reference< uno::XComponentContext > xContext; 163cdf0e10cSrcweir xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext; 164cdf0e10cSrcweir 165cdf0e10cSrcweir uno::Reference< util::XMacroExpander > xMacroExpander; 166cdf0e10cSrcweir if( xContext.is() ) 167cdf0e10cSrcweir xMacroExpander.set( xContext->getValueByName( 168cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander"))), 169cdf0e10cSrcweir UNO_QUERY ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir // import ui strings 172cdf0e10cSrcweir Reference< XMultiServiceFactory > xConfigProvider( 173cdf0e10cSrcweir xServiceFactory->createInstance( 174cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ))), 175cdf0e10cSrcweir UNO_QUERY_THROW ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir UStringMap aTransitionNameMape; 178cdf0e10cSrcweir const OUString aTransitionPath( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Effects/UserInterface/Transitions" ) ); 179cdf0e10cSrcweir implImportLabels( xConfigProvider, aTransitionPath, aTransitionNameMape ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir // read path to transition effects files from config 182cdf0e10cSrcweir Any propValue = uno::makeAny( 183cdf0e10cSrcweir beans::PropertyValue( 184cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath")), -1, 185cdf0e10cSrcweir uno::makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Impress/Misc"))), 186cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE ) ); 187cdf0e10cSrcweir 188cdf0e10cSrcweir Reference<container::XNameAccess> xNameAccess( 189cdf0e10cSrcweir xConfigProvider->createInstanceWithArguments( 190cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationAccess")), 191cdf0e10cSrcweir Sequence<Any>( &propValue, 1 ) ), UNO_QUERY_THROW ); 192cdf0e10cSrcweir uno::Sequence< rtl::OUString > aFiles; 193cdf0e10cSrcweir xNameAccess->getByName( 194cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("TransitionFiles"))) >>= aFiles; 195cdf0e10cSrcweir 196cdf0e10cSrcweir for( sal_Int32 i=0; i<aFiles.getLength(); ++i ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir rtl::OUString aURL = aFiles[i]; 199cdf0e10cSrcweir if( aURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL )) == 0 ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir // cut protocol 202cdf0e10cSrcweir rtl::OUString aMacro( aURL.copy( sizeof ( EXPAND_PROTOCOL ) -1 ) ); 203cdf0e10cSrcweir // decode uric class chars 204cdf0e10cSrcweir aMacro = rtl::Uri::decode( aMacro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); 205cdf0e10cSrcweir // expand macro string 206cdf0e10cSrcweir aURL = xMacroExpander->expandMacros( aMacro ); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir bRet |= importTransitionsFile( rList, 210cdf0e10cSrcweir xServiceFactory, 211cdf0e10cSrcweir aTransitionNameMape, 212cdf0e10cSrcweir aURL ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir return bRet; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir catch( Exception& e ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir (void)e; 220cdf0e10cSrcweir DBG_ERROR( "sd::TransitionPreset::importResources(), Exception cought!" ); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir return bRet; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir TransitionPresetList* TransitionPreset::mpTransitionPresetList = 0; 227cdf0e10cSrcweir 228cdf0e10cSrcweir const TransitionPresetList& TransitionPreset::getTransitionPresetList() 229cdf0e10cSrcweir { 230cdf0e10cSrcweir if( !mpTransitionPresetList ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir OGuard aGuard( Application::GetSolarMutex() ); 233cdf0e10cSrcweir if( !mpTransitionPresetList ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir mpTransitionPresetList = new sd::TransitionPresetList(); 236cdf0e10cSrcweir sd::TransitionPreset::importTransitionPresetList( *mpTransitionPresetList ); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir return *mpTransitionPresetList; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir void TransitionPreset::apply( SdPage* pSlide ) const 244cdf0e10cSrcweir { 245cdf0e10cSrcweir if( pSlide ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir pSlide->setTransitionType( mnTransition ); 248cdf0e10cSrcweir pSlide->setTransitionSubtype( mnSubtype ); 249cdf0e10cSrcweir pSlide->setTransitionDirection( mbDirection ); 250cdf0e10cSrcweir pSlide->setTransitionFadeColor( mnFadeColor ); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir } 255