make sure text operations are not queried by (numeric) value
[LibreOffice.git] / sd / inc / CustomAnimationEffect.hxx
blobe117783c90eab1b2828f6ba45687a6a0183001bb
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 #pragma once
22 #include <com/sun/star/animations/XAnimationNode.hpp>
23 #include <com/sun/star/animations/XTimeContainer.hpp>
24 #include <com/sun/star/animations/XAudio.hpp>
25 #include <com/sun/star/drawing/XShape.hpp>
26 #include <com/sun/star/util/XChangesListener.hpp>
27 #include <vcl/timer.hxx>
28 #include <tools/long.hxx>
29 #include "sddllapi.h"
30 #include <list>
31 #include <vector>
32 #include <map>
33 #include <memory>
35 class SdrPathObj;
36 class SdrModel;
38 namespace sd {
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;
58 public:
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;
68 // attributes
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 setPresetClassAndId( sal_Int16 nPresetClass, const OUString& rPresetId );
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, std::u16string_view rAttributeName, EValue eValue );
130 SAL_DLLPRIVATE bool setProperty( sal_Int32 nNodeType, std::u16string_view 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( const std::vector<sal_Int32>* paragraphNumberingLevel = nullptr );
148 SAL_DLLPRIVATE bool calculateIterateDuration();
150 SAL_DLLPRIVATE void setAudio( const css::uno::Reference< css::animations::XAudio >& xAudio );
151 SAL_DLLPRIVATE bool getStopAudio() const;
152 void setStopAudio();
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; }
159 // helper
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;
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(SdrModel& rTargetModel);
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 sal_Int16 mnFill;
181 double mfBegin;
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
184 sal_Int32 mnGroupId;
185 sal_Int16 mnIterateType;
186 double mfIterateInterval;
187 sal_Int32 mnParaDepth;
188 bool mbHasText;
189 double mfAcceleration;
190 double mfDecelerate;
191 bool mbAutoReverse;
192 sal_Int16 mnTargetSubItem;
193 sal_Int16 mnCommand;
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
216 public:
217 virtual void notify_change() = 0;
219 protected:
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;
229 public:
230 CustomAnimationTextGroup( const css::uno::Reference< css::drawing::XShape >& rTarget, sal_Int32 nGroupId );
232 void reset();
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; }
244 private:
245 EffectSequence maEffects;
246 css::uno::Reference< css::drawing::XShape > maTarget;
248 enum { PARA_LEVELS = 5 };
250 sal_Int32 mnTextGrouping;
251 bool mbAnimateForm;
252 bool mbTextReverse;
253 double mfGroupingAuto;
254 sal_Int32 mnLastPara;
255 sal_Int8 mnDepthFlags[PARA_LEVELS];
256 sal_Int32 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;
266 public:
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, const OUString& rPresetId );
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;
327 protected:
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();
337 SAL_DLLPRIVATE bool getParagraphNumberingLevels( const css::uno::Reference< css::drawing::XShape >& xShape, std::vector< sal_Int32 >& rParagraphNumberingLevel );
339 protected:
340 css::uno::Reference< css::animations::XTimeContainer > mxSequenceRoot;
341 EffectSequence maEffects;
342 std::list< ISequenceListener* > maListeners;
343 CustomAnimationTextGroupMap maGroupMap;
344 sal_Int32 mnSequenceType;
345 css::uno::Reference< css::drawing::XShape > mxEventSource;
348 class MainSequence;
350 class InteractiveSequence final : public EffectSequenceHelper
352 friend class MainSequence;
353 friend class MainSequenceChangeGuard;
355 public:
356 InteractiveSequence( const css::uno::Reference< css::animations::XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence );
358 /** this method rebuilds the animation nodes */
359 virtual void rebuild() override;
361 private:
362 virtual void implRebuild() override;
364 MainSequence* mpMainSequence;
367 typedef std::shared_ptr< InteractiveSequence > InteractiveSequencePtr;
368 typedef std::vector< InteractiveSequencePtr > InteractiveSequenceVector;
370 class SD_DLLPUBLIC MainSequence final : public EffectSequenceHelper, public ISequenceListener
372 friend class UndoAnimation;
373 friend class MainSequenceRebuildGuard;
374 friend class MainSequenceChangeGuard;
376 public:
377 MainSequence();
378 MainSequence( const css::uno::Reference< css::animations::XAnimationNode >& xTimingRootNode );
379 virtual ~MainSequence() override;
381 virtual css::uno::Reference< css::animations::XAnimationNode > getRootNode() override;
382 void reset( const css::uno::Reference< css::animations::XAnimationNode >& xTimingRootNode );
384 /** this method rebuilds the animation nodes */
385 virtual void rebuild() override;
387 virtual CustomAnimationEffectPtr findEffect( const css::uno::Reference< css::animations::XAnimationNode >& xNode ) const override;
389 virtual bool disposeShape( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
390 virtual void insertTextRange( const css::uno::Any& aTarget ) override;
391 virtual void disposeTextRange( const css::uno::Any& aTarget ) override;
392 virtual bool hasEffect( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
393 virtual void onTextChanged( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
395 const InteractiveSequenceVector& getInteractiveSequenceVector() const { return maInteractiveSequenceVector; }
397 virtual void notify_change() override;
399 bool setTrigger( const CustomAnimationEffectPtr& pEffect, const css::uno::Reference< css::drawing::XShape >& xTriggerShape );
401 /** starts a timer that recreates the internal structure from the API core after 1 second */
402 void startRecreateTimer();
404 /** starts a timer that rebuilds the API core from the internal structure after 1 second */
405 void startRebuildTimer();
407 virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const override;
408 virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const override;
410 private:
411 /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
412 process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
413 void lockRebuilds();
414 void unlockRebuilds();
416 DECL_DLLPRIVATE_LINK(onTimerHdl, Timer *, void);
418 virtual void implRebuild() override;
420 void init();
422 void createMainSequence();
423 virtual void reset() override;
425 InteractiveSequencePtr createInteractiveSequence( const css::uno::Reference< css::drawing::XShape >& xShape );
427 InteractiveSequenceVector maInteractiveSequenceVector;
429 css::uno::Reference< css::util::XChangesListener > mxChangesListener;
430 css::uno::Reference< css::animations::XTimeContainer > mxTimingRootNode;
431 Timer maTimer;
432 bool mbTimerMode;
433 bool mbRebuilding;
435 ::tools::Long mnRebuildLockGuard;
436 bool mbPendingRebuildRequest;
437 sal_Int32 mbIgnoreChanges;
440 typedef std::shared_ptr< MainSequence > MainSequencePtr;
442 class MainSequenceRebuildGuard
444 public:
445 MainSequenceRebuildGuard( const MainSequencePtr& pMainSequence );
446 ~MainSequenceRebuildGuard();
448 private:
449 MainSequencePtr mpMainSequence;
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */