bump product version to 4.1.6.2
[LibreOffice.git] / sd / inc / CustomAnimationEffect.hxx
blob8b64065ab6571624180bf8ed8153193b59bccb87
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 _SD_CUSTOMANIMATIONEFFECT_HXX
21 #define _SD_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 <tools/string.hxx>
30 #include <boost/shared_ptr.hpp>
32 #include <comphelper/stl_types.hxx>
33 #include <vcl/timer.hxx>
35 #include <sddllapi.h>
37 #include <list>
38 #include <map>
40 class SdrPathObj;
42 namespace sd {
44 // --------------------------------------------------------------------
46 enum EValue { VALUE_FROM, VALUE_TO, VALUE_BY, VALUE_FIRST, VALUE_LAST };
48 class CustomAnimationEffect;
50 class CustomAnimationPreset;
51 typedef boost::shared_ptr< CustomAnimationPreset > CustomAnimationPresetPtr;
53 typedef boost::shared_ptr< CustomAnimationEffect > CustomAnimationEffectPtr;
55 typedef std::list< CustomAnimationEffectPtr > EffectSequence;
57 class EffectSequenceHelper;
59 class CustomAnimationEffect
61 friend class MainSequence;
62 friend class EffectSequenceHelper;
64 public:
65 SD_DLLPUBLIC CustomAnimationEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
66 SD_DLLPUBLIC virtual ~CustomAnimationEffect();
68 const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& getNode() const { return mxNode; }
69 void setNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
70 void replaceNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
72 CustomAnimationEffectPtr clone() const;
74 // attributes
75 const OUString& getPresetId() const { return maPresetId; }
76 const OUString& getPresetSubType() const { return maPresetSubType; }
77 const OUString& getProperty() const { return maProperty; }
79 sal_Int16 getPresetClass() const { return mnPresetClass; }
80 void setPresetClass( sal_Int16 nPresetClass );
82 sal_Int16 getNodeType() const { return mnNodeType; }
83 SD_DLLPUBLIC void setNodeType( sal_Int16 nNodeType );
85 ::com::sun::star::uno::Any getRepeatCount() const;
86 void setRepeatCount( const ::com::sun::star::uno::Any& rRepeatCount );
88 ::com::sun::star::uno::Any getEnd() const;
89 void setEnd( const ::com::sun::star::uno::Any& rEnd );
91 sal_Int16 getFill() const;
92 void setFill( sal_Int16 nFill );
94 double getBegin() const { return mfBegin; }
95 SD_DLLPUBLIC void setBegin( double fBegin );
97 double getDuration() const { return mfDuration; }
98 SD_DLLPUBLIC void setDuration( double fDuration );
100 double getAbsoluteDuration() const { return mfAbsoluteDuration; }
102 const String& getName() const { return maName; }
103 void setName( const String& rName ) { maName = rName; }
105 sal_Int16 getIterateType() const { return mnIterateType; }
106 SD_DLLPUBLIC void setIterateType( sal_Int16 nIterateType );
108 double getIterateInterval() const { return mfIterateInterval; }
109 SD_DLLPUBLIC void setIterateInterval( double fIterateInterval );
111 ::com::sun::star::uno::Any getTarget() const { return maTarget; }
112 SD_DLLPUBLIC void setTarget( const ::com::sun::star::uno::Any& rTarget );
114 sal_Bool hasAfterEffect() const { return mbHasAfterEffect; }
115 void setHasAfterEffect( sal_Bool bHasAfterEffect ) { mbHasAfterEffect = bHasAfterEffect; }
117 ::com::sun::star::uno::Any getDimColor() const { return maDimColor; }
118 void setDimColor( ::com::sun::star::uno::Any aDimColor ) { maDimColor = aDimColor; }
120 bool IsAfterEffectOnNext() const { return mbAfterEffectOnNextEffect; }
121 void setAfterEffectOnNext( bool bOnNextEffect ) { mbAfterEffectOnNextEffect = bOnNextEffect; }
123 sal_Int32 getParaDepth() const { return mnParaDepth; }
125 sal_Bool hasText() const { return mbHasText; }
127 sal_Int16 getCommand() const { return mnCommand; }
129 double getAcceleration() const { return mfAcceleration; }
130 void setAcceleration( double fAcceleration );
132 double getDecelerate() const { return mfDecelerate; }
133 void setDecelerate( double fDecelerate );
135 sal_Bool getAutoReverse() const { return mbAutoReverse; }
136 void setAutoReverse( sal_Bool bAutoReverse );
138 ::com::sun::star::uno::Any getProperty( sal_Int32 nNodeType, const OUString& rAttributeName, EValue eValue );
139 bool setProperty( sal_Int32 nNodeType, const OUString& rAttributeName, EValue eValue, const ::com::sun::star::uno::Any& rValue );
141 ::com::sun::star::uno::Any getTransformationProperty( sal_Int32 nTransformType, EValue eValue );
142 bool setTransformationProperty( sal_Int32 nTransformType, EValue eValue, const ::com::sun::star::uno::Any& rValue );
144 ::com::sun::star::uno::Any getColor( sal_Int32 nIndex );
145 void setColor( sal_Int32 nIndex, const ::com::sun::star::uno::Any& rColor );
147 ::com::sun::star::uno::Any getRotation();
148 void setRotation( const ::com::sun::star::uno::Any& rRotation );
150 sal_Int32 getGroupId() const { return mnGroupId; }
151 void setGroupId( sal_Int32 nGroupId );
153 sal_Int16 getTargetSubItem() const { return mnTargetSubItem; }
154 SD_DLLPUBLIC void setTargetSubItem( sal_Int16 nSubItem );
156 OUString getPath() const;
157 void setPath( const OUString& rPath );
159 bool checkForText();
160 bool calculateIterateDuration();
162 void setAudio( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAudio >& xAudio );
163 bool getStopAudio() const;
164 SD_DLLPUBLIC void setStopAudio();
165 SD_DLLPUBLIC void createAudio( const ::com::sun::star::uno::Any& rSource, double fVolume = 1.0 );
166 void removeAudio();
167 const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAudio >& getAudio() const { return mxAudio; }
169 EffectSequenceHelper* getEffectSequence() const { return mpEffectSequence; }
171 // helper
172 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > createAfterEffectNode() const throw (com::sun::star::uno::Exception);
173 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTargetShape() const;
175 // static helpers
176 static sal_Int32 get_node_type( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
177 static sal_Int32 getNumberOfSubitems( const ::com::sun::star::uno::Any& aTarget, sal_Int16 nIterateType );
179 SdrPathObj* createSdrPathObjFromPath();
180 void updateSdrPathObjFromPath( SdrPathObj& rPathObj );
181 void updatePathFromSdrPathObj( const SdrPathObj& rPathObj );
183 protected:
184 void setEffectSequence( EffectSequenceHelper* pSequence ) { mpEffectSequence = pSequence; }
186 private:
187 sal_Int16 mnNodeType;
188 OUString maPresetId;
189 OUString maPresetSubType;
190 OUString maProperty;
191 sal_Int16 mnPresetClass;
192 double mfBegin;
193 double mfDuration; // this is the maximum duration of the subeffects
194 double mfAbsoluteDuration; // this is the maximum duration of the subeffects including possible iterations
195 sal_Int32 mnGroupId;
196 sal_Int16 mnIterateType;
197 double mfIterateInterval;
198 sal_Int32 mnParaDepth;
199 sal_Bool mbHasText;
200 double mfAcceleration;
201 double mfDecelerate;
202 sal_Bool mbAutoReverse;
203 sal_Int16 mnTargetSubItem;
204 sal_Int16 mnCommand;
206 EffectSequenceHelper* mpEffectSequence;
208 String maName;
210 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > mxNode;
211 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAudio > mxAudio;
212 ::com::sun::star::uno::Any maTarget;
214 sal_Bool mbHasAfterEffect;
215 ::com::sun::star::uno::Any maDimColor;
216 bool mbAfterEffectOnNextEffect;
219 struct stl_CustomAnimationEffect_search_node_predict
221 stl_CustomAnimationEffect_search_node_predict( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xSearchNode );
222 bool operator()( CustomAnimationEffectPtr pEffect ) const;
223 const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& mxSearchNode;
226 enum ESequenceHint { EFFECT_EDITED, EFFECT_REMOVED, EFFECT_ADDED };
228 /** this listener is implemented by UI components to track changes in the animation core */
229 class ISequenceListener
231 public:
232 virtual void notify_change() = 0;
234 protected:
235 ~ISequenceListener() {}
238 /** this class keeps track of a group of animations that build up
239 a text animation for a single shape */
240 class CustomAnimationTextGroup
242 friend class EffectSequenceHelper;
244 public:
245 CustomAnimationTextGroup( const ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rTarget, sal_Int32 nGroupId );
247 void reset();
248 void addEffect( CustomAnimationEffectPtr& pEffect );
250 const ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& getTarget() const { return maTarget; }
251 const EffectSequence& getEffects() const { return maEffects; }
253 /* -1: as single object, 0: all at once, n > 0: by n Th paragraph */
254 sal_Int32 getTextGrouping() const { return mnTextGrouping; }
256 sal_Bool getAnimateForm() const { return mbAnimateForm; }
257 sal_Bool getTextReverse() const { return mbTextReverse; }
258 double getTextGroupingAuto() const { return mfGroupingAuto; }
260 private:
261 EffectSequence maEffects;
262 ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape > maTarget;
264 enum { PARA_LEVELS = 5 };
266 sal_Int32 mnTextGrouping;
267 sal_Bool mbAnimateForm;
268 sal_Bool mbTextReverse;
269 double mfGroupingAuto;
270 sal_Int32 mnLastPara;
271 sal_Int8 mnDepthFlags[PARA_LEVELS];
272 sal_Int32 mnGroupId;
275 typedef boost::shared_ptr< CustomAnimationTextGroup > CustomAnimationTextGroupPtr;
276 typedef std::map< sal_Int32, CustomAnimationTextGroupPtr > CustomAnimationTextGroupMap;
278 class EffectSequenceHelper
280 friend class MainSequence;
282 public:
283 EffectSequenceHelper();
284 EffectSequenceHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot );
285 virtual ~EffectSequenceHelper();
287 virtual ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > getRootNode();
289 CustomAnimationEffectPtr append( const CustomAnimationPresetPtr& pDescriptor, const ::com::sun::star::uno::Any& rTarget, double fDuration = -1.0 );
290 CustomAnimationEffectPtr append( const SdrPathObj& rPathObj, const ::com::sun::star::uno::Any& rTarget, double fDuration = -1.0 );
291 SD_DLLPUBLIC void append( const CustomAnimationEffectPtr& pEffect );
292 void insert( EffectSequence::iterator& rPos, const CustomAnimationEffectPtr& pEffect );
293 void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, double fDuration = -1.0 );
294 void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, const OUString& rPresetSubType, double fDuration = -1.0 );
295 void remove( const CustomAnimationEffectPtr& pEffect );
297 void create( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
298 void createEffectsequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
299 void processAfterEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
300 void createEffects( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
302 sal_Int32 getCount() const { return sal::static_int_cast< sal_Int32 >( maEffects.size() ); }
304 virtual CustomAnimationEffectPtr findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const;
306 virtual bool disposeShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
307 virtual void insertTextRange( const com::sun::star::uno::Any& aTarget );
308 virtual void disposeTextRange( const com::sun::star::uno::Any& aTarget );
309 virtual bool hasEffect( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
310 virtual void onTextChanged( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
312 /** this must be called if effects from this sequence are changed.
313 the method will call the registered listeners */
314 void update( const CustomAnimationEffectPtr& pEffect );
316 /** this method rebuilds the animation nodes */
317 virtual void rebuild();
319 EffectSequence::iterator getBegin() { return maEffects.begin(); }
320 EffectSequence::iterator getEnd() { return maEffects.end(); }
321 EffectSequence::iterator find( const CustomAnimationEffectPtr& pEffect );
323 EffectSequence& getSequence() { return maEffects; }
325 void addListener( ISequenceListener* pListener );
326 void removeListener( ISequenceListener* pListener );
328 // text group methods
330 CustomAnimationTextGroupPtr findGroup( sal_Int32 nGroupId );
331 SD_DLLPUBLIC CustomAnimationTextGroupPtr createTextGroup( CustomAnimationEffectPtr pEffect, sal_Int32 nTextGrouping, double fTextGroupingAuto, sal_Bool bAnimateForm, sal_Bool bTextReverse );
332 void setTextGrouping( CustomAnimationTextGroupPtr pTextGroup, sal_Int32 nTextGrouping );
333 void setAnimateForm( CustomAnimationTextGroupPtr pTextGroup, sal_Bool bAnimateForm );
334 void setTextGroupingAuto( CustomAnimationTextGroupPtr pTextGroup, double fTextGroupingAuto );
335 void setTextReverse( CustomAnimationTextGroupPtr pTextGroup, sal_Bool bAnimateForm );
337 sal_Int32 getSequenceType() const { return mnSequenceType; }
339 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTriggerShape() const { return mxEventSource; }
340 void setTriggerShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTrigger ) { mxEventSource = xTrigger; }
342 virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
343 virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
345 protected:
346 virtual void implRebuild();
347 virtual void reset();
349 void createTextGroupParagraphEffects( CustomAnimationTextGroupPtr pTextGroup, CustomAnimationEffectPtr pEffect, bool bUsed );
351 void notify_listeners();
353 void updateTextGroups();
355 protected:
356 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > mxSequenceRoot;
357 EffectSequence maEffects;
358 std::list< ISequenceListener* > maListeners;
359 CustomAnimationTextGroupMap maGroupMap;
360 sal_Int32 mnSequenceType;
361 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > mxEventSource;
364 class MainSequence;
366 class InteractiveSequence : public EffectSequenceHelper
368 friend class MainSequence;
369 friend class MainSequenceChangeGuard;
371 public:
372 InteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence );
374 /** this method rebuilds the animation nodes */
375 virtual void rebuild();
377 private:
378 virtual void implRebuild();
380 MainSequence* mpMainSequence;
383 typedef boost::shared_ptr< InteractiveSequence > InteractiveSequencePtr;
384 typedef std::list< InteractiveSequencePtr > InteractiveSequenceList;
386 class MainSequence : public EffectSequenceHelper, public ISequenceListener
388 friend class UndoAnimation;
389 friend class MainSequenceRebuildGuard;
390 friend class MainSequenceChangeGuard;
392 public:
393 MainSequence();
394 MainSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode );
395 ~MainSequence();
397 virtual ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > getRootNode();
398 void reset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode );
400 /** this method rebuilds the animation nodes */
401 virtual void rebuild();
403 virtual CustomAnimationEffectPtr findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const;
405 virtual bool disposeShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
406 virtual void insertTextRange( const com::sun::star::uno::Any& aTarget );
407 virtual void disposeTextRange( const com::sun::star::uno::Any& aTarget );
408 virtual bool hasEffect( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
409 virtual void onTextChanged( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
411 const InteractiveSequenceList& getInteractiveSequenceList() const { return maInteractiveSequenceList; }
413 virtual void notify_change();
415 bool setTrigger( const CustomAnimationEffectPtr& pEffect, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTriggerShape );
417 /** starts a timer that recreates the internal structure from the API core after 1 second */
418 void startRecreateTimer();
420 /** starts a timer that rebuilds the API core from the internal structure after 1 second */
421 void startRebuildTimer();
423 virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
424 virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
426 protected:
427 /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
428 process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
429 void lockRebuilds();
430 void unlockRebuilds();
432 DECL_LINK(onTimerHdl, void *);
434 virtual void implRebuild();
436 void init();
438 void createMainSequence();
439 virtual void reset();
441 InteractiveSequencePtr createInteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape );
443 InteractiveSequenceList maInteractiveSequenceList;
445 ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener > mxChangesListener;
446 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > mxTimingRootNode;
447 Timer maTimer;
448 bool mbTimerMode;
449 bool mbRebuilding;
451 long mnRebuildLockGuard;
452 bool mbPendingRebuildRequest;
453 sal_Int32 mbIgnoreChanges;
456 typedef boost::shared_ptr< MainSequence > MainSequencePtr;
458 class MainSequenceRebuildGuard
460 public:
461 MainSequenceRebuildGuard( const MainSequencePtr& pMainSequence );
462 ~MainSequenceRebuildGuard();
464 private:
465 MainSequencePtr mpMainSequence;
470 #endif // _SD_CUSTOMANIMATIONEFFECT_HXX
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */