1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SD_INC_CUSTOMANIMATIONEFFECT_HXX
21 #define INCLUDED_SD_INC_CUSTOMANIMATIONEFFECT_HXX
23 #include <com/sun/star/animations/XAnimationNode.hpp>
24 #include <com/sun/star/animations/XTimeContainer.hpp>
25 #include <com/sun/star/animations/XAudio.hpp>
26 #include <com/sun/star/drawing/XShape.hpp>
27 #include <com/sun/star/util/XChangesListener.hpp>
28 #include <vcl/timer.hxx>
40 enum class EValue
{ To
, By
};
42 class CustomAnimationEffect
;
44 class CustomAnimationPreset
;
45 typedef std::shared_ptr
< CustomAnimationPreset
> CustomAnimationPresetPtr
;
47 typedef std::shared_ptr
< CustomAnimationEffect
> CustomAnimationEffectPtr
;
49 typedef std::list
< CustomAnimationEffectPtr
> EffectSequence
;
51 class EffectSequenceHelper
;
53 class SD_DLLPUBLIC CustomAnimationEffect final
55 friend class MainSequence
;
56 friend class EffectSequenceHelper
;
59 CustomAnimationEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
60 ~CustomAnimationEffect();
62 SAL_DLLPRIVATE
const css::uno::Reference
< css::animations::XAnimationNode
>& getNode() const { return mxNode
; }
63 SAL_DLLPRIVATE
void setNode( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
64 SAL_DLLPRIVATE
void replaceNode( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
66 SAL_DLLPRIVATE CustomAnimationEffectPtr
clone() const;
69 SAL_DLLPRIVATE
const OUString
& getPresetId() const { return maPresetId
; }
70 SAL_DLLPRIVATE
const OUString
& getPresetSubType() const { return maPresetSubType
; }
71 SAL_DLLPRIVATE
const OUString
& getProperty() const { return maProperty
; }
73 SAL_DLLPRIVATE sal_Int16
getPresetClass() const { return mnPresetClass
; }
74 SAL_DLLPRIVATE
void setPresetClass( sal_Int16 nPresetClass
);
76 SAL_DLLPRIVATE sal_Int16
getNodeType() const { return mnNodeType
; }
77 void setNodeType( sal_Int16 nNodeType
);
79 SAL_DLLPRIVATE
css::uno::Any
getRepeatCount() const;
80 SAL_DLLPRIVATE
void setRepeatCount( const css::uno::Any
& rRepeatCount
);
82 SAL_DLLPRIVATE
css::uno::Any
getEnd() const;
83 SAL_DLLPRIVATE
void setEnd( const css::uno::Any
& rEnd
);
85 SAL_DLLPRIVATE sal_Int16
getFill() const { return mnFill
; }
86 SAL_DLLPRIVATE
void setFill( sal_Int16 nFill
);
88 SAL_DLLPRIVATE
double getBegin() const { return mfBegin
; }
89 void setBegin( double fBegin
);
91 SAL_DLLPRIVATE
double getDuration() const { return mfDuration
; }
92 void setDuration( double fDuration
);
94 SAL_DLLPRIVATE
double getAbsoluteDuration() const { return mfAbsoluteDuration
; }
96 SAL_DLLPRIVATE sal_Int16
getIterateType() const { return mnIterateType
; }
97 void setIterateType( sal_Int16 nIterateType
);
99 SAL_DLLPRIVATE
double getIterateInterval() const { return mfIterateInterval
; }
100 void setIterateInterval( double fIterateInterval
);
102 SAL_DLLPRIVATE
const css::uno::Any
& getTarget() const { return maTarget
; }
103 void setTarget( const css::uno::Any
& rTarget
);
105 SAL_DLLPRIVATE
bool hasAfterEffect() const { return mbHasAfterEffect
; }
106 SAL_DLLPRIVATE
void setHasAfterEffect( bool bHasAfterEffect
) { mbHasAfterEffect
= bHasAfterEffect
; }
108 SAL_DLLPRIVATE
const css::uno::Any
& getDimColor() const { return maDimColor
; }
109 SAL_DLLPRIVATE
void setDimColor( const css::uno::Any
& rDimColor
) { maDimColor
= rDimColor
; }
111 SAL_DLLPRIVATE
bool IsAfterEffectOnNext() const { return mbAfterEffectOnNextEffect
; }
112 SAL_DLLPRIVATE
void setAfterEffectOnNext( bool bOnNextEffect
) { mbAfterEffectOnNextEffect
= bOnNextEffect
; }
114 SAL_DLLPRIVATE sal_Int32
getParaDepth() const { return mnParaDepth
; }
116 SAL_DLLPRIVATE
bool hasText() const { return mbHasText
; }
118 SAL_DLLPRIVATE sal_Int16
getCommand() const { return mnCommand
; }
120 SAL_DLLPRIVATE
double getAcceleration() const { return mfAcceleration
; }
121 SAL_DLLPRIVATE
void setAcceleration( double fAcceleration
);
123 SAL_DLLPRIVATE
double getDecelerate() const { return mfDecelerate
; }
124 SAL_DLLPRIVATE
void setDecelerate( double fDecelerate
);
126 SAL_DLLPRIVATE
bool getAutoReverse() const { return mbAutoReverse
; }
127 SAL_DLLPRIVATE
void setAutoReverse( bool bAutoReverse
);
129 SAL_DLLPRIVATE
css::uno::Any
getProperty( sal_Int32 nNodeType
, const OUString
& rAttributeName
, EValue eValue
);
130 SAL_DLLPRIVATE
bool setProperty( sal_Int32 nNodeType
, const OUString
& rAttributeName
, EValue eValue
, const css::uno::Any
& rValue
);
132 SAL_DLLPRIVATE
css::uno::Any
getTransformationProperty( sal_Int32 nTransformType
, EValue eValue
);
133 SAL_DLLPRIVATE
bool setTransformationProperty( sal_Int32 nTransformType
, EValue eValue
, const css::uno::Any
& rValue
);
135 SAL_DLLPRIVATE
css::uno::Any
getColor( sal_Int32 nIndex
);
136 SAL_DLLPRIVATE
void setColor( sal_Int32 nIndex
, const css::uno::Any
& rColor
);
138 SAL_DLLPRIVATE sal_Int32
getGroupId() const { return mnGroupId
; }
139 SAL_DLLPRIVATE
void setGroupId( sal_Int32 nGroupId
);
141 SAL_DLLPRIVATE sal_Int16
getTargetSubItem() const { return mnTargetSubItem
; }
142 void setTargetSubItem( sal_Int16 nSubItem
);
144 SAL_DLLPRIVATE OUString
getPath() const;
145 SAL_DLLPRIVATE
void setPath( const OUString
& rPath
);
147 SAL_DLLPRIVATE
bool checkForText();
148 SAL_DLLPRIVATE
bool calculateIterateDuration();
150 SAL_DLLPRIVATE
void setAudio( const css::uno::Reference
< css::animations::XAudio
>& xAudio
);
151 SAL_DLLPRIVATE
bool getStopAudio() const;
153 void createAudio( const css::uno::Any
& rSource
);
154 SAL_DLLPRIVATE
void removeAudio();
155 SAL_DLLPRIVATE
const css::uno::Reference
< css::animations::XAudio
>& getAudio() const { return mxAudio
; }
157 SAL_DLLPRIVATE EffectSequenceHelper
* getEffectSequence() const { return mpEffectSequence
; }
160 /// @throws css::uno::Exception
161 SAL_DLLPRIVATE
css::uno::Reference
< css::animations::XAnimationNode
> createAfterEffectNode() const;
162 SAL_DLLPRIVATE
css::uno::Reference
< css::drawing::XShape
> getTargetShape() const;
165 SAL_DLLPRIVATE
static sal_Int32
get_node_type( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
166 SAL_DLLPRIVATE
static sal_Int32
getNumberOfSubitems( const css::uno::Any
& aTarget
, sal_Int16 nIterateType
);
168 SAL_DLLPRIVATE SdrPathObj
* createSdrPathObjFromPath(SdrModel
& rTargetModel
);
169 SAL_DLLPRIVATE
void updateSdrPathObjFromPath( SdrPathObj
& rPathObj
);
170 SAL_DLLPRIVATE
void updatePathFromSdrPathObj( const SdrPathObj
& rPathObj
);
173 SAL_DLLPRIVATE
void setEffectSequence( EffectSequenceHelper
* pSequence
) { mpEffectSequence
= pSequence
; }
175 sal_Int16 mnNodeType
;
177 OUString maPresetSubType
;
179 sal_Int16 mnPresetClass
;
182 double mfDuration
; // this is the maximum duration of the subeffects
183 double mfAbsoluteDuration
; // this is the maximum duration of the subeffects including possible iterations
185 sal_Int16 mnIterateType
;
186 double mfIterateInterval
;
187 sal_Int32 mnParaDepth
;
189 double mfAcceleration
;
192 sal_Int16 mnTargetSubItem
;
195 EffectSequenceHelper
* mpEffectSequence
;
197 css::uno::Reference
< css::animations::XAnimationNode
> mxNode
;
198 css::uno::Reference
< css::animations::XAudio
> mxAudio
;
199 css::uno::Any maTarget
;
201 bool mbHasAfterEffect
;
202 css::uno::Any maDimColor
;
203 bool mbAfterEffectOnNextEffect
;
206 struct stl_CustomAnimationEffect_search_node_predict
208 stl_CustomAnimationEffect_search_node_predict( const css::uno::Reference
< css::animations::XAnimationNode
>& xSearchNode
);
209 bool operator()( const CustomAnimationEffectPtr
& pEffect
) const;
210 const css::uno::Reference
< css::animations::XAnimationNode
>& mxSearchNode
;
213 /** this listener is implemented by UI components to track changes in the animation core */
214 class ISequenceListener
217 virtual void notify_change() = 0;
220 ~ISequenceListener() {}
223 /** this class keeps track of a group of animations that build up
224 a text animation for a single shape */
225 class CustomAnimationTextGroup
227 friend class EffectSequenceHelper
;
230 CustomAnimationTextGroup( const css::uno::Reference
< css::drawing::XShape
>& rTarget
, sal_Int32 nGroupId
);
233 void addEffect( CustomAnimationEffectPtr
const & pEffect
);
235 const EffectSequence
& getEffects() const { return maEffects
; }
237 /* -1: as single object, 0: all at once, n > 0: by n Th paragraph */
238 sal_Int32
getTextGrouping() const { return mnTextGrouping
; }
240 bool getAnimateForm() const { return mbAnimateForm
; }
241 bool getTextReverse() const { return mbTextReverse
; }
242 double getTextGroupingAuto() const { return mfGroupingAuto
; }
245 EffectSequence maEffects
;
246 css::uno::Reference
< css::drawing::XShape
> maTarget
;
248 enum { PARA_LEVELS
= 5 };
250 sal_Int32 mnTextGrouping
;
253 double mfGroupingAuto
;
254 sal_Int32 mnLastPara
;
255 sal_Int8 mnDepthFlags
[PARA_LEVELS
];
256 sal_Int32
const mnGroupId
;
259 typedef std::shared_ptr
< CustomAnimationTextGroup
> CustomAnimationTextGroupPtr
;
260 typedef std::map
< sal_Int32
, CustomAnimationTextGroupPtr
> CustomAnimationTextGroupMap
;
262 class SD_DLLPUBLIC EffectSequenceHelper
264 friend class MainSequence
;
267 SAL_DLLPRIVATE
EffectSequenceHelper();
268 SAL_DLLPRIVATE
EffectSequenceHelper( const css::uno::Reference
< css::animations::XTimeContainer
>& xSequenceRoot
);
269 SAL_DLLPRIVATE
virtual ~EffectSequenceHelper();
271 SAL_DLLPRIVATE
virtual css::uno::Reference
< css::animations::XAnimationNode
> getRootNode();
273 SAL_DLLPRIVATE CustomAnimationEffectPtr
append( const CustomAnimationPresetPtr
& pDescriptor
, const css::uno::Any
& rTarget
, double fDuration
);
274 SAL_DLLPRIVATE CustomAnimationEffectPtr
append( const SdrPathObj
& rPathObj
, const css::uno::Any
& rTarget
, double fDuration
);
275 void append( const CustomAnimationEffectPtr
& pEffect
);
276 SAL_DLLPRIVATE
void replace( const CustomAnimationEffectPtr
& pEffect
, const CustomAnimationPresetPtr
& pDescriptor
, double fDuration
);
277 SAL_DLLPRIVATE
void replace( const CustomAnimationEffectPtr
& pEffect
, const CustomAnimationPresetPtr
& pDescriptor
, const OUString
& rPresetSubType
, double fDuration
);
278 SAL_DLLPRIVATE
void remove( const CustomAnimationEffectPtr
& pEffect
);
279 SAL_DLLPRIVATE
void moveToBeforeEffect( const CustomAnimationEffectPtr
& pEffect
, const CustomAnimationEffectPtr
& pInsertBefore
);
281 SAL_DLLPRIVATE
void create( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
282 SAL_DLLPRIVATE
void createEffectsequence( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
283 SAL_DLLPRIVATE
void processAfterEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
284 SAL_DLLPRIVATE
void createEffects( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
286 SAL_DLLPRIVATE sal_Int32
getCount() const { return sal::static_int_cast
< sal_Int32
>( maEffects
.size() ); }
288 SAL_DLLPRIVATE
virtual CustomAnimationEffectPtr
findEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
) const;
290 SAL_DLLPRIVATE
virtual bool disposeShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
291 SAL_DLLPRIVATE
virtual void insertTextRange( const css::uno::Any
& aTarget
);
292 SAL_DLLPRIVATE
virtual void disposeTextRange( const css::uno::Any
& aTarget
);
293 SAL_DLLPRIVATE
virtual bool hasEffect( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
294 SAL_DLLPRIVATE
virtual void onTextChanged( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
296 /** this method rebuilds the animation nodes */
297 SAL_DLLPRIVATE
virtual void rebuild();
299 SAL_DLLPRIVATE
EffectSequence::iterator
getBegin() { return maEffects
.begin(); }
300 SAL_DLLPRIVATE
EffectSequence::iterator
getEnd() { return maEffects
.end(); }
301 SAL_DLLPRIVATE
EffectSequence::iterator
find( const CustomAnimationEffectPtr
& pEffect
);
303 SAL_DLLPRIVATE EffectSequence
& getSequence() { return maEffects
; }
305 SAL_DLLPRIVATE
void addListener( ISequenceListener
* pListener
);
306 SAL_DLLPRIVATE
void removeListener( ISequenceListener
* pListener
);
308 // text group methods
310 SAL_DLLPRIVATE CustomAnimationTextGroupPtr
findGroup( sal_Int32 nGroupId
);
311 CustomAnimationTextGroupPtr
createTextGroup(const CustomAnimationEffectPtr
& pEffect
,
312 sal_Int32 nTextGrouping
, double fTextGroupingAuto
,
313 bool bAnimateForm
, bool bTextReverse
);
314 SAL_DLLPRIVATE
void setTextGrouping( const CustomAnimationTextGroupPtr
& pTextGroup
, sal_Int32 nTextGrouping
);
315 SAL_DLLPRIVATE
void setAnimateForm( const CustomAnimationTextGroupPtr
& pTextGroup
, bool bAnimateForm
);
316 SAL_DLLPRIVATE
void setTextGroupingAuto( const CustomAnimationTextGroupPtr
& pTextGroup
, double fTextGroupingAuto
);
317 SAL_DLLPRIVATE
void setTextReverse( const CustomAnimationTextGroupPtr
& pTextGroup
, bool bAnimateForm
);
319 SAL_DLLPRIVATE sal_Int32
getSequenceType() const { return mnSequenceType
; }
321 SAL_DLLPRIVATE
const css::uno::Reference
< css::drawing::XShape
>& getTriggerShape() const { return mxEventSource
; }
322 SAL_DLLPRIVATE
void setTriggerShape( const css::uno::Reference
< css::drawing::XShape
>& xTrigger
) { mxEventSource
= xTrigger
; }
324 SAL_DLLPRIVATE
virtual sal_Int32
getOffsetFromEffect( const CustomAnimationEffectPtr
& xEffect
) const;
325 SAL_DLLPRIVATE
virtual CustomAnimationEffectPtr
getEffectFromOffset( sal_Int32 nOffset
) const;
328 SAL_DLLPRIVATE
virtual void implRebuild();
329 SAL_DLLPRIVATE
virtual void reset();
331 SAL_DLLPRIVATE
void createTextGroupParagraphEffects( const CustomAnimationTextGroupPtr
& pTextGroup
, const CustomAnimationEffectPtr
& pEffect
, bool bUsed
);
333 SAL_DLLPRIVATE
void notify_listeners();
335 SAL_DLLPRIVATE
void updateTextGroups();
338 css::uno::Reference
< css::animations::XTimeContainer
> mxSequenceRoot
;
339 EffectSequence maEffects
;
340 std::list
< ISequenceListener
* > maListeners
;
341 CustomAnimationTextGroupMap maGroupMap
;
342 sal_Int32 mnSequenceType
;
343 css::uno::Reference
< css::drawing::XShape
> mxEventSource
;
348 class InteractiveSequence
: public EffectSequenceHelper
350 friend class MainSequence
;
351 friend class MainSequenceChangeGuard
;
354 InteractiveSequence( const css::uno::Reference
< css::animations::XTimeContainer
>& xSequenceRoot
, MainSequence
* pMainSequence
);
356 /** this method rebuilds the animation nodes */
357 virtual void rebuild() override
;
360 virtual void implRebuild() override
;
362 MainSequence
* mpMainSequence
;
365 typedef std::shared_ptr
< InteractiveSequence
> InteractiveSequencePtr
;
366 typedef std::vector
< InteractiveSequencePtr
> InteractiveSequenceVector
;
368 class SAL_DLLPUBLIC_RTTI MainSequence
: public EffectSequenceHelper
, public ISequenceListener
370 friend class UndoAnimation
;
371 friend class MainSequenceRebuildGuard
;
372 friend class MainSequenceChangeGuard
;
376 MainSequence( const css::uno::Reference
< css::animations::XAnimationNode
>& xTimingRootNode
);
377 virtual ~MainSequence() override
;
379 virtual css::uno::Reference
< css::animations::XAnimationNode
> getRootNode() override
;
380 void reset( const css::uno::Reference
< css::animations::XAnimationNode
>& xTimingRootNode
);
382 /** this method rebuilds the animation nodes */
383 virtual void rebuild() override
;
385 virtual CustomAnimationEffectPtr
findEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
) const override
;
387 virtual bool disposeShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
) override
;
388 virtual void insertTextRange( const css::uno::Any
& aTarget
) override
;
389 virtual void disposeTextRange( const css::uno::Any
& aTarget
) override
;
390 virtual bool hasEffect( const css::uno::Reference
< css::drawing::XShape
>& xShape
) override
;
391 virtual void onTextChanged( const css::uno::Reference
< css::drawing::XShape
>& xShape
) override
;
393 const InteractiveSequenceVector
& getInteractiveSequenceVector() const { return maInteractiveSequenceVector
; }
395 virtual void notify_change() override
;
397 bool setTrigger( const CustomAnimationEffectPtr
& pEffect
, const css::uno::Reference
< css::drawing::XShape
>& xTriggerShape
);
399 /** starts a timer that recreates the internal structure from the API core after 1 second */
400 void startRecreateTimer();
402 /** starts a timer that rebuilds the API core from the internal structure after 1 second */
403 void startRebuildTimer();
405 virtual sal_Int32
getOffsetFromEffect( const CustomAnimationEffectPtr
& xEffect
) const override
;
406 virtual CustomAnimationEffectPtr
getEffectFromOffset( sal_Int32 nOffset
) const override
;
409 /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
410 process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
412 void unlockRebuilds();
414 DECL_LINK(onTimerHdl
, Timer
*, void);
416 virtual void implRebuild() override
;
420 void createMainSequence();
421 virtual void reset() override
;
423 InteractiveSequencePtr
createInteractiveSequence( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
425 InteractiveSequenceVector maInteractiveSequenceVector
;
427 css::uno::Reference
< css::util::XChangesListener
> mxChangesListener
;
428 css::uno::Reference
< css::animations::XTimeContainer
> mxTimingRootNode
;
433 long mnRebuildLockGuard
;
434 bool mbPendingRebuildRequest
;
435 sal_Int32 mbIgnoreChanges
;
438 typedef std::shared_ptr
< MainSequence
> MainSequencePtr
;
440 class MainSequenceRebuildGuard
443 MainSequenceRebuildGuard( const MainSequencePtr
& pMainSequence
);
444 ~MainSequenceRebuildGuard();
447 MainSequencePtr mpMainSequence
;
452 #endif // INCLUDED_SD_INC_CUSTOMANIMATIONEFFECT_HXX
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */