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>
39 enum class EValue
{ To
, By
};
41 class CustomAnimationEffect
;
43 class CustomAnimationPreset
;
44 typedef std::shared_ptr
< CustomAnimationPreset
> CustomAnimationPresetPtr
;
46 typedef std::shared_ptr
< CustomAnimationEffect
> CustomAnimationEffectPtr
;
48 typedef std::list
< CustomAnimationEffectPtr
> EffectSequence
;
50 class EffectSequenceHelper
;
52 class SD_DLLPUBLIC CustomAnimationEffect final
54 friend class MainSequence
;
55 friend class EffectSequenceHelper
;
58 CustomAnimationEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
59 ~CustomAnimationEffect();
61 SAL_DLLPRIVATE
const css::uno::Reference
< css::animations::XAnimationNode
>& getNode() const { return mxNode
; }
62 SAL_DLLPRIVATE
void setNode( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
63 SAL_DLLPRIVATE
void replaceNode( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
65 SAL_DLLPRIVATE CustomAnimationEffectPtr
clone() const;
68 SAL_DLLPRIVATE
const OUString
& getPresetId() const { return maPresetId
; }
69 SAL_DLLPRIVATE
const OUString
& getPresetSubType() const { return maPresetSubType
; }
70 SAL_DLLPRIVATE
const OUString
& getProperty() const { return maProperty
; }
72 SAL_DLLPRIVATE sal_Int16
getPresetClass() const { return mnPresetClass
; }
73 SAL_DLLPRIVATE
void setPresetClass( sal_Int16 nPresetClass
);
75 SAL_DLLPRIVATE sal_Int16
getNodeType() const { return mnNodeType
; }
76 void setNodeType( sal_Int16 nNodeType
);
78 SAL_DLLPRIVATE
css::uno::Any
getRepeatCount() const;
79 SAL_DLLPRIVATE
void setRepeatCount( const css::uno::Any
& rRepeatCount
);
81 SAL_DLLPRIVATE
css::uno::Any
getEnd() const;
82 SAL_DLLPRIVATE
void setEnd( const css::uno::Any
& rEnd
);
84 SAL_DLLPRIVATE sal_Int16
getFill() const;
85 SAL_DLLPRIVATE
void setFill( sal_Int16 nFill
);
87 SAL_DLLPRIVATE
double getBegin() const { return mfBegin
; }
88 void setBegin( double fBegin
);
90 SAL_DLLPRIVATE
double getDuration() const { return mfDuration
; }
91 void setDuration( double fDuration
);
93 SAL_DLLPRIVATE
double getAbsoluteDuration() const { return mfAbsoluteDuration
; }
95 SAL_DLLPRIVATE sal_Int16
getIterateType() const { return mnIterateType
; }
96 void setIterateType( sal_Int16 nIterateType
);
98 SAL_DLLPRIVATE
double getIterateInterval() const { return mfIterateInterval
; }
99 void setIterateInterval( double fIterateInterval
);
101 SAL_DLLPRIVATE
const css::uno::Any
& getTarget() const { return maTarget
; }
102 void setTarget( const css::uno::Any
& rTarget
);
104 SAL_DLLPRIVATE
bool hasAfterEffect() const { return mbHasAfterEffect
; }
105 SAL_DLLPRIVATE
void setHasAfterEffect( bool bHasAfterEffect
) { mbHasAfterEffect
= bHasAfterEffect
; }
107 SAL_DLLPRIVATE
const css::uno::Any
& getDimColor() const { return maDimColor
; }
108 SAL_DLLPRIVATE
void setDimColor( const css::uno::Any
& rDimColor
) { maDimColor
= rDimColor
; }
110 SAL_DLLPRIVATE
bool IsAfterEffectOnNext() const { return mbAfterEffectOnNextEffect
; }
111 SAL_DLLPRIVATE
void setAfterEffectOnNext( bool bOnNextEffect
) { mbAfterEffectOnNextEffect
= bOnNextEffect
; }
113 SAL_DLLPRIVATE sal_Int32
getParaDepth() const { return mnParaDepth
; }
115 SAL_DLLPRIVATE
bool hasText() const { return mbHasText
; }
117 SAL_DLLPRIVATE sal_Int16
getCommand() const { return mnCommand
; }
119 SAL_DLLPRIVATE
double getAcceleration() const { return mfAcceleration
; }
120 SAL_DLLPRIVATE
void setAcceleration( double fAcceleration
);
122 SAL_DLLPRIVATE
double getDecelerate() const { return mfDecelerate
; }
123 SAL_DLLPRIVATE
void setDecelerate( double fDecelerate
);
125 SAL_DLLPRIVATE
bool getAutoReverse() const { return mbAutoReverse
; }
126 SAL_DLLPRIVATE
void setAutoReverse( bool bAutoReverse
);
128 SAL_DLLPRIVATE
css::uno::Any
getProperty( sal_Int32 nNodeType
, const OUString
& rAttributeName
, EValue eValue
);
129 SAL_DLLPRIVATE
bool setProperty( sal_Int32 nNodeType
, const OUString
& rAttributeName
, EValue eValue
, const css::uno::Any
& rValue
);
131 SAL_DLLPRIVATE
css::uno::Any
getTransformationProperty( sal_Int32 nTransformType
, EValue eValue
);
132 SAL_DLLPRIVATE
bool setTransformationProperty( sal_Int32 nTransformType
, EValue eValue
, const css::uno::Any
& rValue
);
134 SAL_DLLPRIVATE
css::uno::Any
getColor( sal_Int32 nIndex
);
135 SAL_DLLPRIVATE
void setColor( sal_Int32 nIndex
, const css::uno::Any
& rColor
);
137 SAL_DLLPRIVATE sal_Int32
getGroupId() const { return mnGroupId
; }
138 SAL_DLLPRIVATE
void setGroupId( sal_Int32 nGroupId
);
140 SAL_DLLPRIVATE sal_Int16
getTargetSubItem() const { return mnTargetSubItem
; }
141 void setTargetSubItem( sal_Int16 nSubItem
);
143 SAL_DLLPRIVATE OUString
getPath() const;
144 SAL_DLLPRIVATE
void setPath( const OUString
& rPath
);
146 SAL_DLLPRIVATE
bool checkForText();
147 SAL_DLLPRIVATE
bool calculateIterateDuration();
149 SAL_DLLPRIVATE
void setAudio( const css::uno::Reference
< css::animations::XAudio
>& xAudio
);
150 SAL_DLLPRIVATE
bool getStopAudio() const;
152 void createAudio( const css::uno::Any
& rSource
);
153 SAL_DLLPRIVATE
void removeAudio();
154 SAL_DLLPRIVATE
const css::uno::Reference
< css::animations::XAudio
>& getAudio() const { return mxAudio
; }
156 SAL_DLLPRIVATE EffectSequenceHelper
* getEffectSequence() const { return mpEffectSequence
; }
159 /// @throws css::uno::Exception
160 SAL_DLLPRIVATE
css::uno::Reference
< css::animations::XAnimationNode
> createAfterEffectNode() const;
161 SAL_DLLPRIVATE
css::uno::Reference
< css::drawing::XShape
> getTargetShape() const;
164 SAL_DLLPRIVATE
static sal_Int32
get_node_type( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
165 SAL_DLLPRIVATE
static sal_Int32
getNumberOfSubitems( const css::uno::Any
& aTarget
, sal_Int16 nIterateType
);
167 SAL_DLLPRIVATE SdrPathObj
* createSdrPathObjFromPath(SdrModel
& rTargetModel
);
168 SAL_DLLPRIVATE
void updateSdrPathObjFromPath( SdrPathObj
& rPathObj
);
169 SAL_DLLPRIVATE
void updatePathFromSdrPathObj( const SdrPathObj
& rPathObj
);
172 SAL_DLLPRIVATE
void setEffectSequence( EffectSequenceHelper
* pSequence
) { mpEffectSequence
= pSequence
; }
174 sal_Int16 mnNodeType
;
176 OUString maPresetSubType
;
178 sal_Int16 mnPresetClass
;
180 double mfDuration
; // this is the maximum duration of the subeffects
181 double mfAbsoluteDuration
; // this is the maximum duration of the subeffects including possible iterations
183 sal_Int16 mnIterateType
;
184 double mfIterateInterval
;
185 sal_Int32 mnParaDepth
;
187 double mfAcceleration
;
190 sal_Int16 mnTargetSubItem
;
193 EffectSequenceHelper
* mpEffectSequence
;
195 css::uno::Reference
< css::animations::XAnimationNode
> mxNode
;
196 css::uno::Reference
< css::animations::XAudio
> mxAudio
;
197 css::uno::Any maTarget
;
199 bool mbHasAfterEffect
;
200 css::uno::Any maDimColor
;
201 bool mbAfterEffectOnNextEffect
;
204 struct stl_CustomAnimationEffect_search_node_predict
206 stl_CustomAnimationEffect_search_node_predict( const css::uno::Reference
< css::animations::XAnimationNode
>& xSearchNode
);
207 bool operator()( const CustomAnimationEffectPtr
& pEffect
) const;
208 const css::uno::Reference
< css::animations::XAnimationNode
>& mxSearchNode
;
211 enum ESequenceHint
{ EFFECT_EDITED
, EFFECT_REMOVED
, EFFECT_ADDED
};
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
];
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
);
280 SAL_DLLPRIVATE
void create( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
281 SAL_DLLPRIVATE
void createEffectsequence( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
282 SAL_DLLPRIVATE
void processAfterEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
283 SAL_DLLPRIVATE
void createEffects( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
);
285 SAL_DLLPRIVATE sal_Int32
getCount() const { return sal::static_int_cast
< sal_Int32
>( maEffects
.size() ); }
287 SAL_DLLPRIVATE
virtual CustomAnimationEffectPtr
findEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
) const;
289 SAL_DLLPRIVATE
virtual bool disposeShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
290 SAL_DLLPRIVATE
virtual void insertTextRange( const css::uno::Any
& aTarget
);
291 SAL_DLLPRIVATE
virtual void disposeTextRange( const css::uno::Any
& aTarget
);
292 SAL_DLLPRIVATE
virtual bool hasEffect( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
293 SAL_DLLPRIVATE
virtual void onTextChanged( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
295 /** this method rebuilds the animation nodes */
296 SAL_DLLPRIVATE
virtual void rebuild();
298 SAL_DLLPRIVATE
EffectSequence::iterator
getBegin() { return maEffects
.begin(); }
299 SAL_DLLPRIVATE
EffectSequence::iterator
getEnd() { return maEffects
.end(); }
300 SAL_DLLPRIVATE
EffectSequence::iterator
find( const CustomAnimationEffectPtr
& pEffect
);
302 SAL_DLLPRIVATE EffectSequence
& getSequence() { return maEffects
; }
304 SAL_DLLPRIVATE
void addListener( ISequenceListener
* pListener
);
305 SAL_DLLPRIVATE
void removeListener( ISequenceListener
* pListener
);
307 // text group methods
309 SAL_DLLPRIVATE CustomAnimationTextGroupPtr
findGroup( sal_Int32 nGroupId
);
310 CustomAnimationTextGroupPtr
createTextGroup( CustomAnimationEffectPtr pEffect
, sal_Int32 nTextGrouping
, double fTextGroupingAuto
, bool bAnimateForm
, bool bTextReverse
);
311 SAL_DLLPRIVATE
void setTextGrouping( const CustomAnimationTextGroupPtr
& pTextGroup
, sal_Int32 nTextGrouping
);
312 SAL_DLLPRIVATE
void setAnimateForm( const CustomAnimationTextGroupPtr
& pTextGroup
, bool bAnimateForm
);
313 SAL_DLLPRIVATE
void setTextGroupingAuto( const CustomAnimationTextGroupPtr
& pTextGroup
, double fTextGroupingAuto
);
314 SAL_DLLPRIVATE
void setTextReverse( const CustomAnimationTextGroupPtr
& pTextGroup
, bool bAnimateForm
);
316 SAL_DLLPRIVATE sal_Int32
getSequenceType() const { return mnSequenceType
; }
318 SAL_DLLPRIVATE
const css::uno::Reference
< css::drawing::XShape
>& getTriggerShape() const { return mxEventSource
; }
319 SAL_DLLPRIVATE
void setTriggerShape( const css::uno::Reference
< css::drawing::XShape
>& xTrigger
) { mxEventSource
= xTrigger
; }
321 SAL_DLLPRIVATE
virtual sal_Int32
getOffsetFromEffect( const CustomAnimationEffectPtr
& xEffect
) const;
322 SAL_DLLPRIVATE
virtual CustomAnimationEffectPtr
getEffectFromOffset( sal_Int32 nOffset
) const;
325 SAL_DLLPRIVATE
virtual void implRebuild();
326 SAL_DLLPRIVATE
virtual void reset();
328 SAL_DLLPRIVATE
void createTextGroupParagraphEffects( const CustomAnimationTextGroupPtr
& pTextGroup
, const CustomAnimationEffectPtr
& pEffect
, bool bUsed
);
330 SAL_DLLPRIVATE
void notify_listeners();
332 SAL_DLLPRIVATE
void updateTextGroups();
335 css::uno::Reference
< css::animations::XTimeContainer
> mxSequenceRoot
;
336 EffectSequence maEffects
;
337 std::list
< ISequenceListener
* > maListeners
;
338 CustomAnimationTextGroupMap maGroupMap
;
339 sal_Int32 mnSequenceType
;
340 css::uno::Reference
< css::drawing::XShape
> mxEventSource
;
345 class InteractiveSequence
: public EffectSequenceHelper
347 friend class MainSequence
;
348 friend class MainSequenceChangeGuard
;
351 InteractiveSequence( const css::uno::Reference
< css::animations::XTimeContainer
>& xSequenceRoot
, MainSequence
* pMainSequence
);
353 /** this method rebuilds the animation nodes */
354 virtual void rebuild() override
;
357 virtual void implRebuild() override
;
359 MainSequence
* mpMainSequence
;
362 typedef std::shared_ptr
< InteractiveSequence
> InteractiveSequencePtr
;
363 typedef std::vector
< InteractiveSequencePtr
> InteractiveSequenceVector
;
365 class MainSequence
: public EffectSequenceHelper
, public ISequenceListener
367 friend class UndoAnimation
;
368 friend class MainSequenceRebuildGuard
;
369 friend class MainSequenceChangeGuard
;
373 MainSequence( const css::uno::Reference
< css::animations::XAnimationNode
>& xTimingRootNode
);
374 virtual ~MainSequence() override
;
376 virtual css::uno::Reference
< css::animations::XAnimationNode
> getRootNode() override
;
377 void reset( const css::uno::Reference
< css::animations::XAnimationNode
>& xTimingRootNode
);
379 /** this method rebuilds the animation nodes */
380 virtual void rebuild() override
;
382 virtual CustomAnimationEffectPtr
findEffect( const css::uno::Reference
< css::animations::XAnimationNode
>& xNode
) const override
;
384 virtual bool disposeShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
) override
;
385 virtual void insertTextRange( const css::uno::Any
& aTarget
) override
;
386 virtual void disposeTextRange( const css::uno::Any
& aTarget
) override
;
387 virtual bool hasEffect( const css::uno::Reference
< css::drawing::XShape
>& xShape
) override
;
388 virtual void onTextChanged( const css::uno::Reference
< css::drawing::XShape
>& xShape
) override
;
390 const InteractiveSequenceVector
& getInteractiveSequenceVector() const { return maInteractiveSequenceVector
; }
392 virtual void notify_change() override
;
394 bool setTrigger( const CustomAnimationEffectPtr
& pEffect
, const css::uno::Reference
< css::drawing::XShape
>& xTriggerShape
);
396 /** starts a timer that recreates the internal structure from the API core after 1 second */
397 void startRecreateTimer();
399 /** starts a timer that rebuilds the API core from the internal structure after 1 second */
400 void startRebuildTimer();
402 virtual sal_Int32
getOffsetFromEffect( const CustomAnimationEffectPtr
& xEffect
) const override
;
403 virtual CustomAnimationEffectPtr
getEffectFromOffset( sal_Int32 nOffset
) const override
;
406 /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
407 process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
409 void unlockRebuilds();
411 DECL_LINK(onTimerHdl
, Timer
*, void);
413 virtual void implRebuild() override
;
417 void createMainSequence();
418 virtual void reset() override
;
420 InteractiveSequencePtr
createInteractiveSequence( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
422 InteractiveSequenceVector maInteractiveSequenceVector
;
424 css::uno::Reference
< css::util::XChangesListener
> mxChangesListener
;
425 css::uno::Reference
< css::animations::XTimeContainer
> mxTimingRootNode
;
430 long mnRebuildLockGuard
;
431 bool mbPendingRebuildRequest
;
432 sal_Int32 mbIgnoreChanges
;
435 typedef std::shared_ptr
< MainSequence
> MainSequencePtr
;
437 class MainSequenceRebuildGuard
440 MainSequenceRebuildGuard( const MainSequencePtr
& pMainSequence
);
441 ~MainSequenceRebuildGuard();
444 MainSequencePtr mpMainSequence
;
449 #endif // INCLUDED_SD_INC_CUSTOMANIMATIONEFFECT_HXX
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */