tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / unoidl / randomnode.cxx
bloba11b73a8dc67d211001f94f7e6685aeb3f5f1f75
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 <com/sun/star/animations/XTimeContainer.hpp>
21 #include <com/sun/star/presentation/ParagraphTarget.hpp>
22 #include <com/sun/star/animations/AnimationFill.hpp>
23 #include <com/sun/star/animations/AnimationNodeType.hpp>
24 #include <com/sun/star/animations/XAnimate.hpp>
25 #include <com/sun/star/animations/AnimationRestart.hpp>
26 #include <com/sun/star/animations/ParallelTimeContainer.hpp>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/container/XEnumerationAccess.hpp>
31 #include <com/sun/star/util/XCloneable.hpp>
32 #include <comphelper/processfactory.hxx>
34 #include <cppuhelper/implbase.hxx>
35 #include <cppuhelper/supportsservice.hxx>
36 #include <cppuhelper/weakref.hxx>
37 #include <CustomAnimationPreset.hxx>
38 #include <randomnode.hxx>
39 #include <mutex>
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::UNO_QUERY;
45 using ::com::sun::star::uno::XInterface;
46 using ::com::sun::star::uno::WeakReference;
47 using ::com::sun::star::beans::NamedValue;
48 using ::com::sun::star::lang::IllegalArgumentException;
49 using ::com::sun::star::container::XEnumeration;
50 using ::com::sun::star::container::XEnumerationAccess;
51 using ::com::sun::star::util::XCloneable;
52 using ::com::sun::star::lang::XServiceInfo;
53 using ::com::sun::star::lang::XInitialization;
54 using ::com::sun::star::uno::Type;
55 using ::com::sun::star::uno::XWeak;
56 using ::com::sun::star::presentation::ParagraphTarget;
57 using ::com::sun::star::drawing::XShape;
59 using namespace ::com::sun::star::animations;
61 namespace sd
64 typedef ::cppu::WeakImplHelper< XTimeContainer, XEnumerationAccess, XCloneable, XServiceInfo, XInitialization > RandomAnimationNodeBase;
66 namespace {
68 class RandomAnimationNode : public RandomAnimationNodeBase
70 public:
71 RandomAnimationNode( const RandomAnimationNode& rNode );
72 explicit RandomAnimationNode( sal_Int16 nPresetClass );
73 RandomAnimationNode();
75 // XInitialization
76 void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
78 // XChild
79 Reference< XInterface > SAL_CALL getParent( ) override;
80 void SAL_CALL setParent( const Reference< XInterface >& Parent ) override;
82 // XCloneable
83 virtual Reference< XCloneable > SAL_CALL createClone() override;
85 // XServiceInfo
86 OUString SAL_CALL getImplementationName() override;
87 Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
88 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
90 // XAnimationNode
91 ::sal_Int16 SAL_CALL getType() override;
92 Any SAL_CALL getBegin() override;
93 void SAL_CALL setBegin( const Any& _begin ) override;
94 Any SAL_CALL getDuration() override;
95 void SAL_CALL setDuration( const Any& _duration ) override;
96 Any SAL_CALL getEnd() override;
97 void SAL_CALL setEnd( const Any& _end ) override;
98 Any SAL_CALL getEndSync() override;
99 void SAL_CALL setEndSync( const Any& _endsync ) override;
100 Any SAL_CALL getRepeatCount() override;
101 void SAL_CALL setRepeatCount( const Any& _repeatcount ) override;
102 Any SAL_CALL getRepeatDuration() override;
103 void SAL_CALL setRepeatDuration( const Any& _repeatduration ) override;
104 ::sal_Int16 SAL_CALL getFill() override;
105 void SAL_CALL setFill( ::sal_Int16 _fill ) override;
106 ::sal_Int16 SAL_CALL getFillDefault() override;
107 void SAL_CALL setFillDefault( ::sal_Int16 _filldefault ) override;
108 ::sal_Int16 SAL_CALL getRestart() override;
109 void SAL_CALL setRestart( ::sal_Int16 _restart ) override;
110 ::sal_Int16 SAL_CALL getRestartDefault() override;
111 void SAL_CALL setRestartDefault( ::sal_Int16 _restartdefault ) override;
112 double SAL_CALL getAcceleration() override;
113 void SAL_CALL setAcceleration( double _acceleration ) override;
114 double SAL_CALL getDecelerate() override;
115 void SAL_CALL setDecelerate( double _decelerate ) override;
116 sal_Bool SAL_CALL getAutoReverse() override;
117 void SAL_CALL setAutoReverse( sal_Bool _autoreverse ) override;
118 Sequence< NamedValue > SAL_CALL getUserData() override;
119 void SAL_CALL setUserData( const Sequence< NamedValue >& _userdata ) override;
121 // XElementAccess
122 virtual Type SAL_CALL getElementType() override;
123 virtual sal_Bool SAL_CALL hasElements() override;
125 // XEnumerationAccess
126 virtual Reference< XEnumeration > SAL_CALL createEnumeration() override;
128 // XTimeContainer
129 Reference< XAnimationNode > SAL_CALL insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
130 Reference< XAnimationNode > SAL_CALL insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& refChild ) override;
131 Reference< XAnimationNode > SAL_CALL replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& oldChild ) override;
132 Reference< XAnimationNode > SAL_CALL removeChild( const Reference< XAnimationNode >& oldChild ) override;
133 Reference< XAnimationNode > SAL_CALL appendChild( const Reference< XAnimationNode >& newChild ) override;
135 private:
136 // our first, last and only protection from multi-threads!
137 std::mutex maMutex;
139 sal_Int16 mnPresetClass;
140 WeakReference<XInterface> mxParent;
142 Any maBegin, maDuration, maEnd, maEndSync, maRepeatCount, maRepeatDuration, maTarget;
143 sal_Int16 mnFill, mnFillDefault, mnRestart, mnRestartDefault;
144 double mfAcceleration, mfDecelerate;
145 bool mbAutoReverse;
146 Sequence< NamedValue > maUserData;
148 Reference< XAnimate > mxFirstNode;
153 Reference< XInterface > RandomAnimationNode_createInstance( sal_Int16 nPresetClass )
155 Reference< XInterface > xInt( static_cast<XWeak*>( new RandomAnimationNode( nPresetClass ) ) );
156 return xInt;
159 RandomAnimationNode::RandomAnimationNode( const RandomAnimationNode& rNode )
160 : RandomAnimationNodeBase(rNode),
161 mnPresetClass( rNode.mnPresetClass ),
162 maBegin( rNode.maBegin ),
163 maDuration( rNode.maDuration ),
164 maEnd( rNode.maEnd ),
165 maEndSync( rNode.maEndSync ),
166 maRepeatCount( rNode.maRepeatCount ),
167 maRepeatDuration( rNode.maRepeatDuration ),
168 maTarget( rNode.maTarget ),
169 mnFill( rNode.mnFill ),
170 mnFillDefault( rNode.mnFillDefault ),
171 mnRestart( rNode.mnRestart ),
172 mnRestartDefault( rNode.mnRestartDefault ),
173 mfAcceleration( rNode.mfAcceleration ),
174 mfDecelerate( rNode.mfDecelerate ),
175 mbAutoReverse( rNode.mbAutoReverse ),
176 maUserData( rNode.maUserData )
180 RandomAnimationNode::RandomAnimationNode( sal_Int16 nPresetClass )
181 : mnPresetClass(nPresetClass)
182 , mnFill(AnimationFill::DEFAULT)
183 , mnFillDefault(AnimationFill::INHERIT)
184 , mnRestart(AnimationRestart::DEFAULT)
185 , mnRestartDefault(AnimationRestart::INHERIT)
186 , mfAcceleration(0.0)
187 , mfDecelerate(0.0)
188 , mbAutoReverse(false)
192 RandomAnimationNode::RandomAnimationNode()
193 : RandomAnimationNode(1)
197 // XInitialization
198 void SAL_CALL RandomAnimationNode::initialize( const Sequence< Any >& aArguments )
200 if( aArguments.getLength() != 1 )
201 throw IllegalArgumentException();
203 if( aArguments[0].getValueType() == ::cppu::UnoType<sal_Int16>::get() )
205 aArguments[0] >>= mnPresetClass;
207 else if( aArguments[0].getValueType() != ::cppu::UnoType<ParagraphTarget>::get() )
209 Reference< XShape > xShape;
210 aArguments[0] >>= xShape;
211 if( !xShape.is() )
212 throw IllegalArgumentException();
214 maTarget = aArguments[0];
217 // XAnimationNode
218 sal_Int16 SAL_CALL RandomAnimationNode::getType()
220 return css::animations::AnimationNodeType::PAR;
223 // XAnimationNode
224 Any SAL_CALL RandomAnimationNode::getBegin()
226 std::unique_lock aGuard( maMutex );
227 return maBegin;
230 // XAnimationNode
231 void SAL_CALL RandomAnimationNode::setBegin( const Any& _begin )
233 std::unique_lock aGuard( maMutex );
234 maBegin = _begin;
237 // XAnimationNode
238 Any SAL_CALL RandomAnimationNode::getDuration()
240 std::unique_lock aGuard( maMutex );
241 return maDuration;
244 // XAnimationNode
245 void SAL_CALL RandomAnimationNode::setDuration( const Any& _duration )
247 std::unique_lock aGuard( maMutex );
248 maDuration = _duration;
251 // XAnimationNode
252 Any SAL_CALL RandomAnimationNode::getEnd()
254 std::unique_lock aGuard( maMutex );
255 return maEnd;
258 // XAnimationNode
259 void SAL_CALL RandomAnimationNode::setEnd( const Any& _end )
261 std::unique_lock aGuard( maMutex );
262 maEnd = _end;
265 // XAnimationNode
266 Any SAL_CALL RandomAnimationNode::getEndSync()
268 std::unique_lock aGuard( maMutex );
269 return maEndSync;
272 // XAnimationNode
273 void SAL_CALL RandomAnimationNode::setEndSync( const Any& _endsync )
275 std::unique_lock aGuard( maMutex );
276 maEndSync = _endsync;
279 // XAnimationNode
280 Any SAL_CALL RandomAnimationNode::getRepeatCount()
282 std::unique_lock aGuard( maMutex );
283 return maRepeatCount;
286 // XAnimationNode
287 void SAL_CALL RandomAnimationNode::setRepeatCount( const Any& _repeatcount )
289 std::unique_lock aGuard( maMutex );
290 maRepeatCount = _repeatcount;
293 // XAnimationNode
294 Any SAL_CALL RandomAnimationNode::getRepeatDuration()
296 std::unique_lock aGuard( maMutex );
297 return maRepeatDuration;
300 // XAnimationNode
301 void SAL_CALL RandomAnimationNode::setRepeatDuration( const Any& _repeatduration )
303 std::unique_lock aGuard( maMutex );
304 maRepeatDuration = _repeatduration;
307 // XAnimationNode
308 sal_Int16 SAL_CALL RandomAnimationNode::getFill()
310 std::unique_lock aGuard( maMutex );
311 return mnFill;
314 // XAnimationNode
315 void SAL_CALL RandomAnimationNode::setFill( sal_Int16 _fill )
317 std::unique_lock aGuard( maMutex );
318 mnFill = _fill;
321 // XAnimationNode
322 sal_Int16 SAL_CALL RandomAnimationNode::getFillDefault()
324 std::unique_lock aGuard( maMutex );
325 return mnFillDefault;
328 // XAnimationNode
329 void SAL_CALL RandomAnimationNode::setFillDefault( sal_Int16 _filldefault )
331 std::unique_lock aGuard( maMutex );
332 mnFillDefault = _filldefault;
335 // XAnimationNode
336 sal_Int16 SAL_CALL RandomAnimationNode::getRestart()
338 std::unique_lock aGuard( maMutex );
339 return mnRestart;
342 // XAnimationNode
343 void SAL_CALL RandomAnimationNode::setRestart( sal_Int16 _restart )
345 std::unique_lock aGuard( maMutex );
346 mnRestart = _restart;
349 // XAnimationNode
350 sal_Int16 SAL_CALL RandomAnimationNode::getRestartDefault()
352 std::unique_lock aGuard( maMutex );
353 return mnRestartDefault;
356 // XAnimationNode
357 void SAL_CALL RandomAnimationNode::setRestartDefault( sal_Int16 _restartdefault )
359 std::unique_lock aGuard( maMutex );
360 mnRestartDefault = _restartdefault;
363 // XAnimationNode
364 double SAL_CALL RandomAnimationNode::getAcceleration()
366 std::unique_lock aGuard( maMutex );
367 return mfAcceleration;
370 // XAnimationNode
371 void SAL_CALL RandomAnimationNode::setAcceleration( double _acceleration )
373 std::unique_lock aGuard( maMutex );
374 mfAcceleration = _acceleration;
377 // XAnimationNode
378 double SAL_CALL RandomAnimationNode::getDecelerate()
380 std::unique_lock aGuard( maMutex );
381 return mfDecelerate;
384 // XAnimationNode
385 void SAL_CALL RandomAnimationNode::setDecelerate( double _decelerate )
387 std::unique_lock aGuard( maMutex );
388 mfDecelerate = _decelerate;
391 // XAnimationNode
392 sal_Bool SAL_CALL RandomAnimationNode::getAutoReverse()
394 std::unique_lock aGuard( maMutex );
395 return mbAutoReverse;
398 // XAnimationNode
399 void SAL_CALL RandomAnimationNode::setAutoReverse( sal_Bool _autoreverse )
401 std::unique_lock aGuard( maMutex );
402 mbAutoReverse = _autoreverse;
405 Sequence< NamedValue > SAL_CALL RandomAnimationNode::getUserData()
407 std::unique_lock aGuard( maMutex );
408 return maUserData;
411 void SAL_CALL RandomAnimationNode::setUserData( const Sequence< NamedValue >& _userdata )
413 std::unique_lock aGuard( maMutex );
414 maUserData = _userdata;
417 // XChild
418 Reference< XInterface > SAL_CALL RandomAnimationNode::getParent()
420 std::unique_lock aGuard( maMutex );
421 return mxParent.get();
424 // XChild
425 void SAL_CALL RandomAnimationNode::setParent( const Reference< XInterface >& Parent )
427 std::unique_lock aGuard( maMutex );
428 mxParent = Parent;
431 // XCloneable
432 Reference< XCloneable > SAL_CALL RandomAnimationNode::createClone()
434 std::unique_lock aGuard( maMutex );
435 Reference< XCloneable > xNewNode( new RandomAnimationNode( *this ) );
436 return xNewNode;
439 // XElementAccess
440 Type SAL_CALL RandomAnimationNode::getElementType()
442 return cppu::UnoType<XAnimationNode>::get();
445 // XElementAccess
446 sal_Bool SAL_CALL RandomAnimationNode::hasElements()
448 return true;
451 // XEnumerationAccess
452 Reference< XEnumeration > SAL_CALL RandomAnimationNode::createEnumeration()
454 std::unique_lock aGuard( maMutex );
456 if( !maTarget.hasValue() && mxFirstNode.is() )
458 Any aTarget( mxFirstNode->getTarget() );
459 if( aTarget.hasValue() )
461 maTarget = std::move(aTarget);
462 mxFirstNode.clear();
466 Reference< XEnumeration > xEnum;
468 Reference< XEnumerationAccess > aEnumAccess( CustomAnimationPresets::getCustomAnimationPresets().getRandomPreset( mnPresetClass ), UNO_QUERY );
470 if( aEnumAccess.is() )
472 Reference< XEnumeration > xEnumeration = aEnumAccess->createEnumeration();
473 if( xEnumeration.is() )
475 while( xEnumeration->hasMoreElements() )
477 Reference< XAnimate > xAnimate( xEnumeration->nextElement(), UNO_QUERY );
478 if( xAnimate.is() )
479 xAnimate->setTarget( maTarget );
482 xEnum = aEnumAccess->createEnumeration();
484 else
486 // no presets? give empty node!
487 Reference< XParallelTimeContainer > xTimeContainer = ParallelTimeContainer::create( comphelper::getProcessComponentContext() );
488 xEnum = xTimeContainer->createEnumeration();
491 return xEnum;
494 // XTimeContainer
495 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertBefore( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
497 return appendChild( newChild );
500 // XTimeContainer
501 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::insertAfter( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
503 return appendChild( newChild );
506 // XTimeContainer
507 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::replaceChild( const Reference< XAnimationNode >& newChild, const Reference< XAnimationNode >& )
509 return appendChild( newChild );
512 // XTimeContainer
513 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::removeChild( const Reference< XAnimationNode >& oldChild )
515 return oldChild;
518 // XTimeContainer
519 Reference< XAnimationNode > SAL_CALL RandomAnimationNode::appendChild( const Reference< XAnimationNode >& newChild )
521 Reference< XAnimate > xAnimate( newChild, UNO_QUERY );
522 if( xAnimate.is() )
524 Any aTarget( xAnimate->getTarget() );
525 if( aTarget.hasValue() )
526 maTarget = std::move(aTarget);
529 if( !maTarget.hasValue() && !mxFirstNode.is() )
530 mxFirstNode = std::move(xAnimate);
532 return newChild;
535 // XServiceInfo
536 OUString RandomAnimationNode::getImplementationName()
538 return u"sd::RandomAnimationNode"_ustr ;
541 // XServiceInfo
542 sal_Bool RandomAnimationNode::supportsService(const OUString& ServiceName)
544 return cppu::supportsService(this, ServiceName);
547 // XServiceInfo
548 Sequence< OUString > RandomAnimationNode::getSupportedServiceNames()
550 return { u"com.sun.star.animations.ParallelTimeContainer"_ustr, u"com.sun.star.comp.sd.RandomAnimationNode"_ustr };
555 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
556 RandomAnimationNode_get_implementation(css::uno::XComponentContext*,
557 css::uno::Sequence<css::uno::Any> const &)
559 return cppu::acquire(new sd::RandomAnimationNode());
563 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */