merge the formfield patch from ooo-build
[ooovba.git] / sd / inc / CustomAnimationEffect.hxx
blob3d0fbe73b9e189ea376c57eaf234ea66ca2f8da9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CustomAnimationEffect.hxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SD_CUSTOMANIMATIONEFFECT_HXX
32 #define _SD_CUSTOMANIMATIONEFFECT_HXX
34 #include <com/sun/star/animations/XAnimationNode.hpp>
35 #include <com/sun/star/animations/XTimeContainer.hpp>
36 #include <com/sun/star/animations/XAudio.hpp>
37 #include <com/sun/star/drawing/XShape.hpp>
38 #include <com/sun/star/util/XChangesListener.hpp>
39 #include <tools/string.hxx>
41 #include <boost/shared_ptr.hpp>
43 #include <comphelper/stl_types.hxx>
44 #include <vcl/timer.hxx>
46 #include <sddllapi.h>
48 #include <list>
49 #include <map>
51 class SdrPathObj;
53 namespace sd {
55 // --------------------------------------------------------------------
57 enum EValue { VALUE_FROM, VALUE_TO, VALUE_BY, VALUE_FIRST, VALUE_LAST };
59 class CustomAnimationEffect;
60 class AnimationTrigger;
62 class CustomAnimationPreset;
63 typedef boost::shared_ptr< CustomAnimationPreset > CustomAnimationPresetPtr;
65 typedef boost::shared_ptr< CustomAnimationEffect > CustomAnimationEffectPtr;
67 typedef std::list< CustomAnimationEffectPtr > EffectSequence;
69 class EffectSequenceHelper;
71 class CustomAnimationEffect
73 friend class MainSequence;
74 friend class EffectSequenceHelper;
76 public:
77 SD_DLLPUBLIC CustomAnimationEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
78 SD_DLLPUBLIC virtual ~CustomAnimationEffect();
80 const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& getNode() const { return mxNode; }
81 void setNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
82 void replaceNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
84 CustomAnimationEffectPtr clone() const;
86 // attributes
87 const rtl::OUString& getPresetId() const { return maPresetId; }
88 const rtl::OUString& getPresetSubType() const { return maPresetSubType; }
89 const rtl::OUString& getProperty() const { return maProperty; }
91 sal_Int16 getPresetClass() const { return mnPresetClass; }
92 void setPresetClass( sal_Int16 nPresetClass );
94 sal_Int16 getNodeType() const { return mnNodeType; }
95 SD_DLLPUBLIC void setNodeType( sal_Int16 nNodeType );
97 ::com::sun::star::uno::Any getRepeatCount() const;
98 void setRepeatCount( const ::com::sun::star::uno::Any& rRepeatCount );
100 ::com::sun::star::uno::Any getEnd() const;
101 void setEnd( const ::com::sun::star::uno::Any& rEnd );
103 sal_Int16 getFill() const;
104 void setFill( sal_Int16 nFill );
106 double getBegin() const { return mfBegin; }
107 SD_DLLPUBLIC void setBegin( double fBegin );
109 double getDuration() const { return mfDuration; }
110 SD_DLLPUBLIC void setDuration( double fDuration );
112 double getAbsoluteDuration() const { return mfAbsoluteDuration; }
114 const String& getName() const { return maName; }
115 void setName( const String& rName ) { maName = rName; }
117 sal_Int16 getIterateType() const { return mnIterateType; }
118 SD_DLLPUBLIC void setIterateType( sal_Int16 nIterateType );
120 double getIterateInterval() const { return mfIterateInterval; }
121 SD_DLLPUBLIC void setIterateInterval( double fIterateInterval );
123 ::com::sun::star::uno::Any getTarget() const { return maTarget; }
124 SD_DLLPUBLIC void setTarget( const ::com::sun::star::uno::Any& rTarget );
126 sal_Bool hasAfterEffect() const { return mbHasAfterEffect; }
127 void setHasAfterEffect( sal_Bool bHasAfterEffect ) { mbHasAfterEffect = bHasAfterEffect; }
129 ::com::sun::star::uno::Any getDimColor() const { return maDimColor; }
130 void setDimColor( ::com::sun::star::uno::Any aDimColor ) { maDimColor = aDimColor; }
132 bool IsAfterEffectOnNext() const { return mbAfterEffectOnNextEffect; }
133 void setAfterEffectOnNext( bool bOnNextEffect ) { mbAfterEffectOnNextEffect = bOnNextEffect; }
135 sal_Int32 getParaDepth() const { return mnParaDepth; }
137 sal_Bool hasText() const { return mbHasText; }
139 sal_Int16 getCommand() const { return mnCommand; }
141 double getAcceleration() const { return mfAcceleration; }
142 void setAcceleration( double fAcceleration );
144 double getDecelerate() const { return mfDecelerate; }
145 void setDecelerate( double fDecelerate );
147 sal_Bool getAutoReverse() const { return mbAutoReverse; }
148 void setAutoReverse( sal_Bool bAutoReverse );
150 ::com::sun::star::uno::Any getProperty( sal_Int32 nNodeType, const rtl::OUString& rAttributeName, EValue eValue );
151 bool setProperty( sal_Int32 nNodeType, const rtl::OUString& rAttributeName, EValue eValue, const ::com::sun::star::uno::Any& rValue );
153 ::com::sun::star::uno::Any getTransformationProperty( sal_Int32 nTransformType, EValue eValue );
154 bool setTransformationProperty( sal_Int32 nTransformType, EValue eValue, const ::com::sun::star::uno::Any& rValue );
156 ::com::sun::star::uno::Any getColor( sal_Int32 nIndex );
157 void setColor( sal_Int32 nIndex, const ::com::sun::star::uno::Any& rColor );
159 ::com::sun::star::uno::Any getRotation();
160 void setRotation( const ::com::sun::star::uno::Any& rRotation );
162 sal_Int32 getGroupId() const { return mnGroupId; }
163 void setGroupId( sal_Int32 nGroupId );
165 sal_Int16 getTargetSubItem() const { return mnTargetSubItem; }
166 SD_DLLPUBLIC void setTargetSubItem( sal_Int16 nSubItem );
168 ::rtl::OUString getPath() const;
169 void setPath( const ::rtl::OUString& rPath );
171 bool checkForText();
172 bool calculateIterateDuration();
174 void setAudio( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAudio >& xAudio );
175 bool getStopAudio() const;
176 SD_DLLPUBLIC void setStopAudio();
177 SD_DLLPUBLIC void createAudio( const ::com::sun::star::uno::Any& rSource, double fVolume = 1.0 );
178 void removeAudio();
179 const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAudio >& getAudio() const { return mxAudio; }
181 EffectSequenceHelper* getEffectSequence() const { return mpEffectSequence; }
183 // helper
184 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > createAfterEffectNode() const throw (com::sun::star::uno::Exception);
185 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTargetShape() const;
187 // static helpers
188 static sal_Int32 get_node_type( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
189 static sal_Int32 getNumberOfSubitems( const ::com::sun::star::uno::Any& aTarget, sal_Int16 nIterateType );
191 SdrPathObj* createSdrPathObjFromPath();
192 void updateSdrPathObjFromPath( SdrPathObj& rPathObj );
193 void updatePathFromSdrPathObj( const SdrPathObj& rPathObj );
195 protected:
196 void setEffectSequence( EffectSequenceHelper* pSequence ) { mpEffectSequence = pSequence; }
198 private:
199 sal_Int16 mnNodeType;
200 rtl::OUString maPresetId;
201 rtl::OUString maPresetSubType;
202 rtl::OUString maProperty;
203 sal_Int16 mnPresetClass;
204 double mfBegin;
205 double mfDuration; // this is the maximum duration of the subeffects
206 double mfAbsoluteDuration; // this is the maximum duration of the subeffects including possible iterations
207 sal_Int32 mnGroupId;
208 sal_Int16 mnIterateType;
209 double mfIterateInterval;
210 sal_Int32 mnParaDepth;
211 sal_Bool mbHasText;
212 double mfAcceleration;
213 double mfDecelerate;
214 sal_Bool mbAutoReverse;
215 sal_Int16 mnTargetSubItem;
216 sal_Int16 mnCommand;
218 EffectSequenceHelper* mpEffectSequence;
220 String maName;
222 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > mxNode;
223 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAudio > mxAudio;
224 ::com::sun::star::uno::Any maTarget;
226 sal_Bool mbHasAfterEffect;
227 ::com::sun::star::uno::Any maDimColor;
228 bool mbAfterEffectOnNextEffect;
231 struct stl_CustomAnimationEffect_search_node_predict
233 stl_CustomAnimationEffect_search_node_predict( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xSearchNode );
234 bool operator()( CustomAnimationEffectPtr pEffect ) const;
235 const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& mxSearchNode;
238 enum ESequenceHint { EFFECT_EDITED, EFFECT_REMOVED, EFFECT_ADDED };
240 /** this listener is implemented by UI components to track changes in the animation core */
241 class ISequenceListener
243 public:
244 virtual void notify_change() = 0;
247 /** this class keeps track of a group of animations that build up
248 a text animation for a single shape */
249 class CustomAnimationTextGroup
251 friend class EffectSequenceHelper;
253 public:
254 CustomAnimationTextGroup( const ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rTarget, sal_Int32 nGroupId );
256 void reset();
257 void addEffect( CustomAnimationEffectPtr& pEffect );
259 const ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& getTarget() const { return maTarget; }
260 const EffectSequence& getEffects() const { return maEffects; }
262 /* -1: as single object, 0: all at once, n > 0: by n Th paragraph */
263 sal_Int32 getTextGrouping() const { return mnTextGrouping; }
265 sal_Bool getAnimateForm() const { return mbAnimateForm; }
266 sal_Bool getTextReverse() const { return mbTextReverse; }
267 double getTextGroupingAuto() const { return mfGroupingAuto; }
269 private:
270 EffectSequence maEffects;
271 ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape > maTarget;
273 sal_Int32 mnTextGrouping;
274 sal_Bool mbAnimateForm;
275 sal_Bool mbTextReverse;
276 double mfGroupingAuto;
277 sal_Int32 mnLastPara;
278 sal_Int8 mnDepthFlags[5];
279 sal_Int32 mnGroupId;
282 typedef boost::shared_ptr< CustomAnimationTextGroup > CustomAnimationTextGroupPtr;
283 typedef std::map< sal_Int32, CustomAnimationTextGroupPtr > CustomAnimationTextGroupMap;
285 class EffectSequenceHelper
287 friend class MainSequence;
289 public:
290 EffectSequenceHelper();
291 EffectSequenceHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot );
292 virtual ~EffectSequenceHelper();
294 virtual ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > getRootNode();
296 CustomAnimationEffectPtr append( const CustomAnimationPresetPtr& pDescriptor, const ::com::sun::star::uno::Any& rTarget, double fDuration = -1.0 );
297 CustomAnimationEffectPtr append( const SdrPathObj& rPathObj, const ::com::sun::star::uno::Any& rTarget, double fDuration = -1.0 );
298 SD_DLLPUBLIC void append( const CustomAnimationEffectPtr& pEffect );
299 void insert( EffectSequence::iterator& rPos, const CustomAnimationEffectPtr& pEffect );
300 void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, double fDuration = -1.0 );
301 void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, const rtl::OUString& rPresetSubType, double fDuration = -1.0 );
302 void remove( const CustomAnimationEffectPtr& pEffect );
304 void create( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
305 void createEffectsequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
306 void processAfterEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
307 void createEffects( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
309 sal_Int32 getCount() const { return sal::static_int_cast< sal_Int32 >( maEffects.size() ); }
311 virtual CustomAnimationEffectPtr findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const;
313 virtual bool disposeShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
314 virtual void insertTextRange( const com::sun::star::uno::Any& aTarget );
315 virtual void disposeTextRange( const com::sun::star::uno::Any& aTarget );
316 virtual bool hasEffect( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
317 virtual void onTextChanged( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
319 /** this must be called if effects from this sequence are changed.
320 the method will call the registered listeners */
321 void update( const CustomAnimationEffectPtr& pEffect );
323 /** this method rebuilds the animation nodes */
324 virtual void rebuild();
326 EffectSequence::iterator getBegin() { return maEffects.begin(); }
327 EffectSequence::iterator getEnd() { return maEffects.end(); }
328 EffectSequence::iterator find( const CustomAnimationEffectPtr& pEffect );
330 EffectSequence& getSequence() { return maEffects; }
332 void addListener( ISequenceListener* pListener );
333 void removeListener( ISequenceListener* pListener );
335 // text group methods
337 CustomAnimationTextGroupPtr findGroup( sal_Int32 nGroupId );
338 SD_DLLPUBLIC CustomAnimationTextGroupPtr createTextGroup( CustomAnimationEffectPtr pEffect, sal_Int32 nTextGrouping, double fTextGroupingAuto, sal_Bool bAnimateForm, sal_Bool bTextReverse );
339 void setTextGrouping( CustomAnimationTextGroupPtr pTextGroup, sal_Int32 nTextGrouping );
340 void setAnimateForm( CustomAnimationTextGroupPtr pTextGroup, sal_Bool bAnimateForm );
341 void setTextGroupingAuto( CustomAnimationTextGroupPtr pTextGroup, double fTextGroupingAuto );
342 void setTextReverse( CustomAnimationTextGroupPtr pTextGroup, sal_Bool bAnimateForm );
344 sal_Int32 getSequenceType() const { return mnSequenceType; }
346 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTriggerShape() const { return mxEventSource; }
347 void setTriggerShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTrigger ) { mxEventSource = xTrigger; }
349 virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
350 virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
352 protected:
353 virtual void implRebuild();
354 virtual void reset();
356 void createTextGroupParagraphEffects( CustomAnimationTextGroupPtr pTextGroup, CustomAnimationEffectPtr pEffect, bool bUsed );
358 void notify_listeners();
360 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > createParallelTimeContainer() const;
362 void updateTextGroups();
364 protected:
365 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > mxSequenceRoot;
366 EffectSequence maEffects;
367 std::list< ISequenceListener* > maListeners;
368 CustomAnimationTextGroupMap maGroupMap;
369 sal_Int32 mnSequenceType;
370 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > mxEventSource;
373 class MainSequence;
375 class InteractiveSequence : public EffectSequenceHelper
377 friend class MainSequence;
378 friend class MainSequenceChangeGuard;
380 public:
381 InteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence );
383 /** this method rebuilds the animation nodes */
384 virtual void rebuild();
386 private:
387 virtual void implRebuild();
389 MainSequence* mpMainSequence;
392 typedef boost::shared_ptr< InteractiveSequence > InteractiveSequencePtr;
393 typedef std::list< InteractiveSequencePtr > InteractiveSequenceList;
395 class MainSequence : public EffectSequenceHelper, public ISequenceListener
397 friend class UndoAnimation;
398 friend class MainSequenceRebuildGuard;
399 friend class MainSequenceChangeGuard;
401 public:
402 MainSequence();
403 MainSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode );
404 ~MainSequence();
406 virtual ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > getRootNode();
407 void reset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode );
409 /** this method rebuilds the animation nodes */
410 virtual void rebuild();
412 virtual CustomAnimationEffectPtr findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const;
414 virtual bool disposeShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
415 virtual void insertTextRange( const com::sun::star::uno::Any& aTarget );
416 virtual void disposeTextRange( const com::sun::star::uno::Any& aTarget );
417 virtual bool hasEffect( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
418 virtual void onTextChanged( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
420 const InteractiveSequenceList& getInteractiveSequenceList() const { return maInteractiveSequenceList; }
422 virtual void notify_change();
424 bool setTrigger( const CustomAnimationEffectPtr& pEffect, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTriggerShape );
426 /** starts a timer that recreates the internal structure from the API core after 1 second */
427 void startRecreateTimer();
429 /** starts a timer that rebuilds the API core from the internal structure after 1 second */
430 void startRebuildTimer();
432 virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
433 virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
435 protected:
436 /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
437 process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
438 void lockRebuilds();
439 void unlockRebuilds();
441 DECL_LINK( onTimerHdl, Timer * );
443 virtual void implRebuild();
445 void init();
447 void createMainSequence();
448 virtual void reset();
450 InteractiveSequencePtr createInteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape );
452 InteractiveSequenceList maInteractiveSequenceList;
454 ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener > mxChangesListener;
455 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > mxTimingRootNode;
456 Timer maTimer;
457 bool mbTimerMode;
458 bool mbRebuilding;
460 long mnRebuildLockGuard;
461 bool mbPendingRebuildRequest;
462 sal_Int32 mbIgnoreChanges;
465 typedef boost::shared_ptr< MainSequence > MainSequencePtr;
467 class MainSequenceRebuildGuard
469 public:
470 MainSequenceRebuildGuard( const MainSequencePtr& pMainSequence );
471 ~MainSequenceRebuildGuard();
473 private:
474 MainSequencePtr mpMainSequence;
479 #endif // _SD_CUSTOMANIMATIONEFFECT_HXX