build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / sd / inc / CustomAnimationEffect.hxx
blobf9391a4b50cb7237e5a3ca74aa2f70a0da3134eb
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 #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>
29 #include <vcl/timer.hxx>
31 #include <sddllapi.h>
33 #include <list>
34 #include <map>
35 #include <memory>
37 class SdrPathObj;
39 namespace sd {
41 enum EValue { VALUE_FROM, VALUE_TO, VALUE_BY, VALUE_FIRST, VALUE_LAST };
43 class CustomAnimationEffect;
45 class CustomAnimationPreset;
46 typedef std::shared_ptr< CustomAnimationPreset > CustomAnimationPresetPtr;
48 typedef std::shared_ptr< CustomAnimationEffect > CustomAnimationEffectPtr;
50 typedef std::list< CustomAnimationEffectPtr > EffectSequence;
52 class EffectSequenceHelper;
54 class SD_DLLPUBLIC CustomAnimationEffect final
56 friend class MainSequence;
57 friend class EffectSequenceHelper;
59 public:
60 CustomAnimationEffect( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
61 ~CustomAnimationEffect();
63 SAL_DLLPRIVATE const css::uno::Reference< css::animations::XAnimationNode >& getNode() const { return mxNode; }
64 SAL_DLLPRIVATE void setNode( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
65 SAL_DLLPRIVATE void replaceNode( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
67 SAL_DLLPRIVATE CustomAnimationEffectPtr clone() const;
69 // attributes
70 SAL_DLLPRIVATE const OUString& getPresetId() const { return maPresetId; }
71 SAL_DLLPRIVATE const OUString& getPresetSubType() const { return maPresetSubType; }
72 SAL_DLLPRIVATE const OUString& getProperty() const { return maProperty; }
74 SAL_DLLPRIVATE sal_Int16 getPresetClass() const { return mnPresetClass; }
75 SAL_DLLPRIVATE void setPresetClass( sal_Int16 nPresetClass );
77 SAL_DLLPRIVATE sal_Int16 getNodeType() const { return mnNodeType; }
78 void setNodeType( sal_Int16 nNodeType );
80 SAL_DLLPRIVATE css::uno::Any getRepeatCount() const;
81 SAL_DLLPRIVATE void setRepeatCount( const css::uno::Any& rRepeatCount );
83 SAL_DLLPRIVATE css::uno::Any getEnd() const;
84 SAL_DLLPRIVATE void setEnd( const css::uno::Any& rEnd );
86 SAL_DLLPRIVATE sal_Int16 getFill() const;
87 SAL_DLLPRIVATE void setFill( sal_Int16 nFill );
89 SAL_DLLPRIVATE double getBegin() const { return mfBegin; }
90 void setBegin( double fBegin );
92 SAL_DLLPRIVATE double getDuration() const { return mfDuration; }
93 void setDuration( double fDuration );
95 SAL_DLLPRIVATE double getAbsoluteDuration() const { return mfAbsoluteDuration; }
97 SAL_DLLPRIVATE sal_Int16 getIterateType() const { return mnIterateType; }
98 void setIterateType( sal_Int16 nIterateType );
100 SAL_DLLPRIVATE double getIterateInterval() const { return mfIterateInterval; }
101 void setIterateInterval( double fIterateInterval );
103 SAL_DLLPRIVATE const css::uno::Any& getTarget() const { return maTarget; }
104 void setTarget( const css::uno::Any& rTarget );
106 SAL_DLLPRIVATE bool hasAfterEffect() const { return mbHasAfterEffect; }
107 SAL_DLLPRIVATE void setHasAfterEffect( bool bHasAfterEffect ) { mbHasAfterEffect = bHasAfterEffect; }
109 SAL_DLLPRIVATE const css::uno::Any& getDimColor() const { return maDimColor; }
110 SAL_DLLPRIVATE void setDimColor( const css::uno::Any& rDimColor ) { maDimColor = rDimColor; }
112 SAL_DLLPRIVATE bool IsAfterEffectOnNext() const { return mbAfterEffectOnNextEffect; }
113 SAL_DLLPRIVATE void setAfterEffectOnNext( bool bOnNextEffect ) { mbAfterEffectOnNextEffect = bOnNextEffect; }
115 SAL_DLLPRIVATE sal_Int32 getParaDepth() const { return mnParaDepth; }
117 SAL_DLLPRIVATE bool hasText() const { return mbHasText; }
119 SAL_DLLPRIVATE sal_Int16 getCommand() const { return mnCommand; }
121 SAL_DLLPRIVATE double getAcceleration() const { return mfAcceleration; }
122 SAL_DLLPRIVATE void setAcceleration( double fAcceleration );
124 SAL_DLLPRIVATE double getDecelerate() const { return mfDecelerate; }
125 SAL_DLLPRIVATE void setDecelerate( double fDecelerate );
127 SAL_DLLPRIVATE bool getAutoReverse() const { return mbAutoReverse; }
128 SAL_DLLPRIVATE void setAutoReverse( bool bAutoReverse );
130 SAL_DLLPRIVATE css::uno::Any getProperty( sal_Int32 nNodeType, const OUString& rAttributeName, EValue eValue );
131 SAL_DLLPRIVATE bool setProperty( sal_Int32 nNodeType, const OUString& rAttributeName, EValue eValue, const css::uno::Any& rValue );
133 SAL_DLLPRIVATE css::uno::Any getTransformationProperty( sal_Int32 nTransformType, EValue eValue );
134 SAL_DLLPRIVATE bool setTransformationProperty( sal_Int32 nTransformType, EValue eValue, const css::uno::Any& rValue );
136 SAL_DLLPRIVATE css::uno::Any getColor( sal_Int32 nIndex );
137 SAL_DLLPRIVATE void setColor( sal_Int32 nIndex, const css::uno::Any& rColor );
139 SAL_DLLPRIVATE sal_Int32 getGroupId() const { return mnGroupId; }
140 SAL_DLLPRIVATE void setGroupId( sal_Int32 nGroupId );
142 SAL_DLLPRIVATE sal_Int16 getTargetSubItem() const { return mnTargetSubItem; }
143 void setTargetSubItem( sal_Int16 nSubItem );
145 SAL_DLLPRIVATE OUString getPath() const;
146 SAL_DLLPRIVATE void setPath( const OUString& rPath );
148 SAL_DLLPRIVATE bool checkForText();
149 SAL_DLLPRIVATE bool calculateIterateDuration();
151 SAL_DLLPRIVATE void setAudio( const css::uno::Reference< css::animations::XAudio >& xAudio );
152 SAL_DLLPRIVATE bool getStopAudio() const;
153 void setStopAudio();
154 void createAudio( const css::uno::Any& rSource );
155 SAL_DLLPRIVATE void removeAudio();
156 SAL_DLLPRIVATE const css::uno::Reference< css::animations::XAudio >& getAudio() const { return mxAudio; }
158 SAL_DLLPRIVATE EffectSequenceHelper* getEffectSequence() const { return mpEffectSequence; }
160 // helper
161 SAL_DLLPRIVATE css::uno::Reference< css::animations::XAnimationNode > createAfterEffectNode() const throw (css::uno::Exception);
162 SAL_DLLPRIVATE css::uno::Reference< css::drawing::XShape > getTargetShape() const;
164 // static helpers
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();
169 SAL_DLLPRIVATE void updateSdrPathObjFromPath( SdrPathObj& rPathObj );
170 SAL_DLLPRIVATE void updatePathFromSdrPathObj( const SdrPathObj& rPathObj );
172 private:
173 SAL_DLLPRIVATE void setEffectSequence( EffectSequenceHelper* pSequence ) { mpEffectSequence = pSequence; }
175 sal_Int16 mnNodeType;
176 OUString maPresetId;
177 OUString maPresetSubType;
178 OUString maProperty;
179 sal_Int16 mnPresetClass;
180 double mfBegin;
181 double mfDuration; // this is the maximum duration of the subeffects
182 double mfAbsoluteDuration; // this is the maximum duration of the subeffects including possible iterations
183 sal_Int32 mnGroupId;
184 sal_Int16 mnIterateType;
185 double mfIterateInterval;
186 sal_Int32 mnParaDepth;
187 bool mbHasText;
188 double mfAcceleration;
189 double mfDecelerate;
190 bool mbAutoReverse;
191 sal_Int16 mnTargetSubItem;
192 sal_Int16 mnCommand;
194 EffectSequenceHelper* mpEffectSequence;
196 css::uno::Reference< css::animations::XAnimationNode > mxNode;
197 css::uno::Reference< css::animations::XAudio > mxAudio;
198 css::uno::Any maTarget;
200 bool mbHasAfterEffect;
201 css::uno::Any maDimColor;
202 bool mbAfterEffectOnNextEffect;
205 struct stl_CustomAnimationEffect_search_node_predict
207 stl_CustomAnimationEffect_search_node_predict( const css::uno::Reference< css::animations::XAnimationNode >& xSearchNode );
208 bool operator()( const CustomAnimationEffectPtr& pEffect ) const;
209 const css::uno::Reference< css::animations::XAnimationNode >& mxSearchNode;
212 enum ESequenceHint { EFFECT_EDITED, EFFECT_REMOVED, EFFECT_ADDED };
214 /** this listener is implemented by UI components to track changes in the animation core */
215 class ISequenceListener
217 public:
218 virtual void notify_change() = 0;
220 protected:
221 ~ISequenceListener() {}
224 /** this class keeps track of a group of animations that build up
225 a text animation for a single shape */
226 class CustomAnimationTextGroup
228 friend class EffectSequenceHelper;
230 public:
231 CustomAnimationTextGroup( const css::uno::Reference< css::drawing::XShape >& rTarget, sal_Int32 nGroupId );
233 void reset();
234 void addEffect( CustomAnimationEffectPtr& pEffect );
236 const EffectSequence& getEffects() const { return maEffects; }
238 /* -1: as single object, 0: all at once, n > 0: by n Th paragraph */
239 sal_Int32 getTextGrouping() const { return mnTextGrouping; }
241 bool getAnimateForm() const { return mbAnimateForm; }
242 bool getTextReverse() const { return mbTextReverse; }
243 double getTextGroupingAuto() const { return mfGroupingAuto; }
245 private:
246 EffectSequence maEffects;
247 css::uno::Reference< css::drawing::XShape > maTarget;
249 enum { PARA_LEVELS = 5 };
251 sal_Int32 mnTextGrouping;
252 bool mbAnimateForm;
253 bool mbTextReverse;
254 double mfGroupingAuto;
255 sal_Int32 mnLastPara;
256 sal_Int8 mnDepthFlags[PARA_LEVELS];
257 sal_Int32 mnGroupId;
260 typedef std::shared_ptr< CustomAnimationTextGroup > CustomAnimationTextGroupPtr;
261 typedef std::map< sal_Int32, CustomAnimationTextGroupPtr > CustomAnimationTextGroupMap;
263 class SD_DLLPUBLIC EffectSequenceHelper
265 friend class MainSequence;
267 public:
268 SAL_DLLPRIVATE EffectSequenceHelper();
269 SAL_DLLPRIVATE EffectSequenceHelper( const css::uno::Reference< css::animations::XTimeContainer >& xSequenceRoot );
270 SAL_DLLPRIVATE virtual ~EffectSequenceHelper();
272 SAL_DLLPRIVATE virtual css::uno::Reference< css::animations::XAnimationNode > getRootNode();
274 SAL_DLLPRIVATE CustomAnimationEffectPtr append( const CustomAnimationPresetPtr& pDescriptor, const css::uno::Any& rTarget, double fDuration );
275 SAL_DLLPRIVATE CustomAnimationEffectPtr append( const SdrPathObj& rPathObj, const css::uno::Any& rTarget, double fDuration );
276 void append( const CustomAnimationEffectPtr& pEffect );
277 SAL_DLLPRIVATE void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, double fDuration );
278 SAL_DLLPRIVATE void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, const OUString& rPresetSubType, double fDuration );
279 SAL_DLLPRIVATE void remove( const CustomAnimationEffectPtr& pEffect );
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( CustomAnimationEffectPtr pEffect, sal_Int32 nTextGrouping, double fTextGroupingAuto, bool bAnimateForm, bool bTextReverse );
312 SAL_DLLPRIVATE void setTextGrouping( const CustomAnimationTextGroupPtr& pTextGroup, sal_Int32 nTextGrouping );
313 SAL_DLLPRIVATE void setAnimateForm( const CustomAnimationTextGroupPtr& pTextGroup, bool bAnimateForm );
314 SAL_DLLPRIVATE void setTextGroupingAuto( const CustomAnimationTextGroupPtr& pTextGroup, double fTextGroupingAuto );
315 SAL_DLLPRIVATE void setTextReverse( const CustomAnimationTextGroupPtr& pTextGroup, bool bAnimateForm );
317 SAL_DLLPRIVATE sal_Int32 getSequenceType() const { return mnSequenceType; }
319 SAL_DLLPRIVATE const css::uno::Reference< css::drawing::XShape >& getTriggerShape() const { return mxEventSource; }
320 SAL_DLLPRIVATE void setTriggerShape( const css::uno::Reference< css::drawing::XShape >& xTrigger ) { mxEventSource = xTrigger; }
322 SAL_DLLPRIVATE virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
323 SAL_DLLPRIVATE virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
325 protected:
326 SAL_DLLPRIVATE virtual void implRebuild();
327 SAL_DLLPRIVATE virtual void reset();
329 SAL_DLLPRIVATE void createTextGroupParagraphEffects( const CustomAnimationTextGroupPtr& pTextGroup, const CustomAnimationEffectPtr& pEffect, bool bUsed );
331 SAL_DLLPRIVATE void notify_listeners();
333 SAL_DLLPRIVATE void updateTextGroups();
335 protected:
336 css::uno::Reference< css::animations::XTimeContainer > mxSequenceRoot;
337 EffectSequence maEffects;
338 std::list< ISequenceListener* > maListeners;
339 CustomAnimationTextGroupMap maGroupMap;
340 sal_Int32 mnSequenceType;
341 css::uno::Reference< css::drawing::XShape > mxEventSource;
344 class MainSequence;
346 class InteractiveSequence : public EffectSequenceHelper
348 friend class MainSequence;
349 friend class MainSequenceChangeGuard;
351 public:
352 InteractiveSequence( const css::uno::Reference< css::animations::XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence );
354 /** this method rebuilds the animation nodes */
355 virtual void rebuild() override;
357 private:
358 virtual void implRebuild() override;
360 MainSequence* mpMainSequence;
363 typedef std::shared_ptr< InteractiveSequence > InteractiveSequencePtr;
364 typedef std::list< InteractiveSequencePtr > InteractiveSequenceList;
366 class MainSequence : public EffectSequenceHelper, public ISequenceListener
368 friend class UndoAnimation;
369 friend class MainSequenceRebuildGuard;
370 friend class MainSequenceChangeGuard;
372 public:
373 MainSequence();
374 MainSequence( const css::uno::Reference< css::animations::XAnimationNode >& xTimingRootNode );
375 virtual ~MainSequence() override;
377 virtual css::uno::Reference< css::animations::XAnimationNode > getRootNode() override;
378 void reset( const css::uno::Reference< css::animations::XAnimationNode >& xTimingRootNode );
380 /** this method rebuilds the animation nodes */
381 virtual void rebuild() override;
383 virtual CustomAnimationEffectPtr findEffect( const css::uno::Reference< css::animations::XAnimationNode >& xNode ) const override;
385 virtual bool disposeShape( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
386 virtual void insertTextRange( const css::uno::Any& aTarget ) override;
387 virtual void disposeTextRange( const css::uno::Any& aTarget ) override;
388 virtual bool hasEffect( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
389 virtual void onTextChanged( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
391 const InteractiveSequenceList& getInteractiveSequenceList() const { return maInteractiveSequenceList; }
393 virtual void notify_change() override;
395 bool setTrigger( const CustomAnimationEffectPtr& pEffect, const css::uno::Reference< css::drawing::XShape >& xTriggerShape );
397 /** starts a timer that recreates the internal structure from the API core after 1 second */
398 void startRecreateTimer();
400 /** starts a timer that rebuilds the API core from the internal structure after 1 second */
401 void startRebuildTimer();
403 virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const override;
404 virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const override;
406 protected:
407 /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
408 process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
409 void lockRebuilds();
410 void unlockRebuilds();
412 DECL_LINK(onTimerHdl, Timer *, void);
414 virtual void implRebuild() override;
416 void init();
418 void createMainSequence();
419 virtual void reset() override;
421 InteractiveSequencePtr createInteractiveSequence( const css::uno::Reference< css::drawing::XShape >& xShape );
423 InteractiveSequenceList maInteractiveSequenceList;
425 css::uno::Reference< css::util::XChangesListener > mxChangesListener;
426 css::uno::Reference< css::animations::XTimeContainer > mxTimingRootNode;
427 Timer maTimer;
428 bool mbTimerMode;
429 bool mbRebuilding;
431 long mnRebuildLockGuard;
432 bool mbPendingRebuildRequest;
433 sal_Int32 mbIgnoreChanges;
436 typedef std::shared_ptr< MainSequence > MainSequencePtr;
438 class MainSequenceRebuildGuard
440 public:
441 MainSequenceRebuildGuard( const MainSequencePtr& pMainSequence );
442 ~MainSequenceRebuildGuard();
444 private:
445 MainSequencePtr mpMainSequence;
450 #endif // INCLUDED_SD_INC_CUSTOMANIMATIONEFFECT_HXX
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */