xmlsecurity: fix --without-system-nss build
[LibreOffice.git] / sd / source / core / TransitionPreset.cxx
blob8b831e3f640821adf4eb7659d5731e65ba9be1cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <set>
22 #include <com/sun/star/animations/XTransitionFilter.hpp>
23 #include <com/sun/star/container/XEnumerationAccess.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/configuration/theDefaultProvider.hpp>
26 #include <com/sun/star/beans/NamedValue.hpp>
27 #include <com/sun/star/animations/AnimationNodeType.hpp>
28 #include <com/sun/star/animations/TransitionType.hpp>
29 #include <com/sun/star/animations/TransitionSubType.hpp>
30 #include <unotools/configmgr.hxx>
31 #include <comphelper/getexpandeduri.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <comphelper/propertysequence.hxx>
34 #include <comphelper/lok.hxx>
35 #include <unotools/syslocaleoptions.hxx>
36 #include <officecfg/Office/Impress.hxx>
37 #include <officecfg/Office/UI/Effects.hxx>
38 #include <comphelper/diagnose_ex.hxx>
40 #include <sal/log.hxx>
41 #include <vcl/svapp.hxx>
43 #include <CustomAnimationPreset.hxx>
44 #include <TransitionPreset.hxx>
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::animations;
49 using ::com::sun::star::uno::UNO_QUERY_THROW;
50 using ::com::sun::star::uno::Any;
51 using ::com::sun::star::uno::Sequence;
52 using ::com::sun::star::uno::Reference;
53 using ::com::sun::star::uno::Exception;
54 using ::com::sun::star::lang::XMultiServiceFactory;
55 using ::com::sun::star::container::XEnumerationAccess;
56 using ::com::sun::star::container::XEnumeration;
57 using ::com::sun::star::beans::NamedValue;
59 namespace sd {
61 TransitionPreset::TransitionPreset( const css::uno::Reference< css::animations::XAnimationNode >& xNode )
63 // first locate preset id
64 const Sequence< NamedValue > aUserData( xNode->getUserData() );
65 const NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
66 [](const NamedValue& rProp) { return rProp.Name == "preset-id"; });
67 if (pProp != aUserData.end())
68 pProp->Value >>= maPresetId;
70 // second, locate transition filter element
71 Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
72 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), css::uno::UNO_SET_THROW );
73 Reference< XTransitionFilter > xTransition( xEnumeration->nextElement(), UNO_QUERY_THROW );
75 mnTransition = xTransition->getTransition();
76 mnSubtype = xTransition->getSubtype();
77 mbDirection = xTransition->getDirection();
78 mnFadeColor = xTransition->getFadeColor();
81 bool TransitionPreset::importTransitionsFile( TransitionPresetList& rList,
82 Reference< XMultiServiceFactory > const & xServiceFactory,
83 const OUString& aURL )
85 SAL_INFO("sd.transitions", "Importing " << aURL);
87 Reference< container::XNameAccess > xTransitionSets( officecfg::Office::UI::Effects::UserInterface::TransitionSets::get() );
88 Reference< container::XNameAccess > xTransitionGroups( officecfg::Office::UI::Effects::UserInterface::TransitionGroups::get() );
89 Reference< container::XNameAccess > xTransitionVariants( officecfg::Office::UI::Effects::UserInterface::TransitionVariants::get() );
90 Reference< container::XNameAccess > xTransitions( officecfg::Office::UI::Effects::UserInterface::Transitions::get() );
92 // import transition presets
93 Reference< XAnimationNode > xAnimationNode;
95 const std::set<sal_Int16> LOKSupportedTransitionTypes = {
96 TransitionType::BARWIPE,
97 TransitionType::BOXWIPE,
98 TransitionType::FOURBOXWIPE,
99 TransitionType::ELLIPSEWIPE,
100 TransitionType::CLOCKWIPE,
101 TransitionType::PINWHEELWIPE,
102 TransitionType::PUSHWIPE,
103 TransitionType::SLIDEWIPE,
104 TransitionType::FADE,
105 TransitionType::RANDOMBARWIPE,
106 TransitionType::CHECKERBOARDWIPE,
107 TransitionType::DISSOLVE,
108 TransitionType::SNAKEWIPE,
109 TransitionType::PARALLELSNAKESWIPE,
110 TransitionType::IRISWIPE,
111 TransitionType::BARNDOORWIPE,
112 TransitionType::VEEWIPE,
113 TransitionType::ZIGZAGWIPE,
114 TransitionType::BARNZIGZAGWIPE,
115 TransitionType::FANWIPE,
116 TransitionType::SINGLESWEEPWIPE,
117 TransitionType::WATERFALLWIPE,
118 TransitionType::SPIRALWIPE,
119 TransitionType::MISCDIAGONALWIPE,
120 TransitionType::BOXSNAKESWIPE,
121 TransitionType::BLINDSWIPE,
122 TransitionType::MISCSHAPEWIPE,
123 TransitionType::ZOOM
126 const std::set<sal_Int16> LOKSupportedTransitionSubTypes = {
127 TransitionSubType::DEFAULT,
128 TransitionSubType::LEFTTORIGHT,
129 TransitionSubType::TOPTOBOTTOM,
130 TransitionSubType::CORNERSIN,
131 TransitionSubType::CORNERSOUT,
132 TransitionSubType::VERTICAL,
133 TransitionSubType::HORIZONTAL,
134 TransitionSubType::DOWN,
135 TransitionSubType::CIRCLE,
136 TransitionSubType::CLOCKWISETWELVE,
137 TransitionSubType::CLOCKWISETHREE,
138 TransitionSubType::CLOCKWISESIX,
139 TransitionSubType::CLOCKWISENINE,
140 TransitionSubType::TWOBLADEVERTICAL,
141 TransitionSubType::TWOBLADEHORIZONTAL,
142 TransitionSubType::FOURBLADE,
143 TransitionSubType::FROMLEFT,
144 TransitionSubType::FROMTOP,
145 TransitionSubType::FROMRIGHT,
146 TransitionSubType::FROMBOTTOM,
147 TransitionSubType::CROSSFADE,
148 TransitionSubType::FADETOCOLOR,
149 TransitionSubType::FADEFROMCOLOR,
150 TransitionSubType::FADEOVERCOLOR,
151 TransitionSubType::THREEBLADE,
152 TransitionSubType::EIGHTBLADE,
153 TransitionSubType::ONEBLADE,
154 TransitionSubType::ACROSS,
155 TransitionSubType::TOPLEFTVERTICAL,
156 TransitionSubType::TOPLEFTHORIZONTAL,
157 TransitionSubType::TOPLEFTDIAGONAL,
158 TransitionSubType::TOPRIGHTDIAGONAL,
159 TransitionSubType::BOTTOMRIGHTDIAGONAL,
160 TransitionSubType::BOTTOMLEFTDIAGONAL,
161 TransitionSubType::RECTANGLE,
162 TransitionSubType::DIAMOND,
163 TransitionSubType::TOPLEFT,
164 TransitionSubType::TOPRIGHT,
165 TransitionSubType::BOTTOMRIGHT,
166 TransitionSubType::BOTTOMLEFT,
167 TransitionSubType::TOPCENTER,
168 TransitionSubType::RIGHTCENTER,
169 TransitionSubType::BOTTOMCENTER,
170 TransitionSubType::LEFTCENTER,
171 TransitionSubType::LEFT,
172 TransitionSubType::UP,
173 TransitionSubType::RIGHT,
174 TransitionSubType::DIAGONALBOTTOMLEFT,
175 TransitionSubType::DIAGONALTOPLEFT,
176 TransitionSubType::CENTERTOP,
177 TransitionSubType::CENTERRIGHT,
178 TransitionSubType::TOP,
179 TransitionSubType::BOTTOM,
180 TransitionSubType::CLOCKWISETOP,
181 TransitionSubType::CLOCKWISERIGHT,
182 TransitionSubType::CLOCKWISEBOTTOM,
183 TransitionSubType::CLOCKWISELEFT,
184 TransitionSubType::CLOCKWISETOPLEFT,
185 TransitionSubType::COUNTERCLOCKWISEBOTTOMLEFT,
186 TransitionSubType::CLOCKWISEBOTTOMRIGHT,
187 TransitionSubType::COUNTERCLOCKWISETOPRIGHT,
188 TransitionSubType::VERTICALLEFT,
189 TransitionSubType::VERTICALRIGHT,
190 TransitionSubType::HORIZONTALLEFT,
191 TransitionSubType::HORIZONTALRIGHT,
192 TransitionSubType::TOPLEFTCLOCKWISE,
193 TransitionSubType::TOPRIGHTCLOCKWISE,
194 TransitionSubType::BOTTOMRIGHTCLOCKWISE,
195 TransitionSubType::BOTTOMLEFTCLOCKWISE,
196 TransitionSubType::TOPLEFTCOUNTERCLOCKWISE,
197 TransitionSubType::TOPRIGHTCOUNTERCLOCKWISE,
198 TransitionSubType::BOTTOMRIGHTCOUNTERCLOCKWISE,
199 TransitionSubType::BOTTOMLEFTCOUNTERCLOCKWISE,
200 TransitionSubType::DOUBLEBARNDOOR,
201 TransitionSubType::DOUBLEDIAMOND,
202 TransitionSubType::VERTICALTOPSAME,
203 TransitionSubType::VERTICALBOTTOMSAME,
204 TransitionSubType::VERTICALTOPLEFTOPPOSITE,
205 TransitionSubType::VERTICALBOTTOMLEFTOPPOSITE,
206 TransitionSubType::HORIZONTALLEFTSAME,
207 TransitionSubType::HORIZONTALRIGHTSAME,
208 TransitionSubType::HORIZONTALTOPLEFTOPPOSITE,
209 TransitionSubType::HORIZONTALTOPRIGHTOPPOSITE,
210 TransitionSubType::DIAGONALBOTTOMLEFTOPPOSITE,
211 TransitionSubType::DIAGONALTOPLEFTOPPOSITE,
212 TransitionSubType::TWOBOXTOP,
213 TransitionSubType::TWOBOXBOTTOM,
214 TransitionSubType::TWOBOXLEFT,
215 TransitionSubType::TWOBOXRIGHT,
216 TransitionSubType::FOURBOXVERTICAL,
217 TransitionSubType::FOURBOXHORIZONTAL,
218 TransitionSubType::COMBVERTICAL,
219 TransitionSubType::COMBHORIZONTAL,
220 TransitionSubType::FANOUTHORIZONTAL,
221 TransitionSubType::HEART,
222 TransitionSubType::ROTATEIN
225 const std::set<sal_Int16> LOKMiscShapeWipeNonSupportedTransitionSubTypes = {
226 TransitionSubType::DIAMOND,
227 TransitionSubType::HEART,
228 TransitionSubType::CIRCLE,
229 TransitionSubType::VERTICAL,
230 TransitionSubType::TOPLEFT
233 try {
234 xAnimationNode = implImportEffects( xServiceFactory, aURL );
235 Reference< XEnumerationAccess > xEnumerationAccess( xAnimationNode, UNO_QUERY_THROW );
236 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), css::uno::UNO_SET_THROW );
238 while( xEnumeration->hasMoreElements() )
240 Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
241 if( xChildNode->getType() == AnimationNodeType::PAR )
243 TransitionPresetPtr pPreset( new TransitionPreset( xChildNode ) );
245 if( comphelper::LibreOfficeKit::isActive() )
247 sal_Int16 eTransitionType = pPreset->getTransition();
248 sal_Int16 eTransitionSubType = pPreset->getSubtype();
249 if( LOKSupportedTransitionTypes.find(eTransitionType) == LOKSupportedTransitionTypes.end()
250 || LOKSupportedTransitionSubTypes.find(eTransitionSubType) == LOKSupportedTransitionSubTypes.end() )
252 continue;
255 if( eTransitionType == TransitionType::MISCSHAPEWIPE
256 && LOKMiscShapeWipeNonSupportedTransitionSubTypes.find(eTransitionSubType) != LOKMiscShapeWipeNonSupportedTransitionSubTypes.end() )
258 continue;
262 OUString aPresetId( pPreset->getPresetId() );
264 if( !aPresetId.isEmpty() )
266 Reference< container::XNameAccess > xTransitionNode;
268 if (xTransitions->hasByName( aPresetId ) &&
269 (xTransitions->getByName( aPresetId ) >>= xTransitionNode) &&
270 xTransitionNode.is() )
272 OUString sSet;
273 OUString sVariant;
275 xTransitionNode->getByName( u"Set"_ustr ) >>= sSet;
276 xTransitionNode->getByName( u"Variant"_ustr ) >>= sVariant;
278 Reference< container::XNameAccess > xSetNode;
280 xTransitionSets->getByName( sSet ) >>= xSetNode;
281 if( xSetNode.is() )
283 pPreset->maSetId = sSet;
284 xSetNode->getByName( u"Label"_ustr ) >>= sSet;
285 pPreset->maSetLabel = sSet;
287 OUString sGroup;
289 xSetNode->getByName( u"Group"_ustr ) >>= sGroup;
291 Reference< container::XNameAccess > xGroupNode;
292 xTransitionGroups->getByName( sGroup ) >>= xGroupNode;
294 if( xGroupNode.is() )
296 xGroupNode->getByName( u"Label"_ustr ) >>= sGroup;
297 if( !sVariant.isEmpty() )
299 Reference< container::XNameAccess > xVariantNode;
300 xTransitionVariants->getByName( sVariant ) >>= xVariantNode;
301 if( xVariantNode.is() )
303 xVariantNode->getByName( u"Label"_ustr ) >>= sVariant;
304 pPreset->maVariantLabel = sVariant;
308 pPreset->maSetLabel = sSet;
309 SAL_INFO("sd.transitions", aPresetId << ": " << sGroup << "/" << sSet << (sVariant.isEmpty() ? OUString() : OUString("/" + sVariant)));
311 rList.push_back( pPreset );
313 else
314 SAL_WARN("sd.transitions", "group node " << sGroup << " not found");
316 else
317 SAL_WARN("sd.transitions", "set node " << sSet << " not found");
319 else
320 SAL_WARN("sd.transitions", "transition node " << aPresetId << " not found");
323 else
325 SAL_WARN("sd.transitions", " malformed xml configuration file " << aURL );
326 break;
329 } catch( Exception& ) {
330 return false;
333 return true;
336 bool TransitionPreset::importTransitionPresetList( TransitionPresetList& rList )
338 if (comphelper::IsFuzzing())
339 return false;
341 bool bRet = false;
345 const uno::Reference< uno::XComponentContext >& xContext(
346 comphelper::getProcessComponentContext() );
347 Reference< XMultiServiceFactory > xServiceFactory(
348 xContext->getServiceManager(), UNO_QUERY_THROW );
350 // import ui strings
351 Reference< XMultiServiceFactory > xConfigProvider =
352 configuration::theDefaultProvider::get( xContext );
354 // read path to transition effects files from config
355 uno::Sequence< OUString > aFiles;
356 aFiles = officecfg::Office::Impress::Misc::TransitionFiles::get();
357 for (const auto& rFile : aFiles)
359 OUString aURL = comphelper::getExpandedUri(xContext, rFile);
361 bRet |= importTransitionsFile( rList,
362 xServiceFactory,
363 aURL );
366 return bRet;
368 catch( Exception& )
370 TOOLS_WARN_EXCEPTION( "sd", "sd::TransitionPreset::importResources()" );
373 return bRet;
376 std::map<OUString, TransitionPresetList> sd::TransitionPreset::mPresetsMap;
378 const TransitionPresetList& TransitionPreset::getTransitionPresetList()
380 // Support localization per-view. Currently not useful for Desktop
381 // but very much critical for LOK. The cache now is per-language.
382 const OUString aLang = comphelper::LibreOfficeKit::isActive()
383 ? comphelper::LibreOfficeKit::getLanguageTag().getBcp47()
384 : SvtSysLocaleOptions().GetLanguageTag().getBcp47();
386 SolarMutexGuard aGuard;
387 const auto it = mPresetsMap.find(aLang);
388 if (it != mPresetsMap.end())
389 return it->second;
391 TransitionPresetList& rList = mPresetsMap[aLang];
392 sd::TransitionPreset::importTransitionPresetList(rList);
393 return rList;
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */