1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CustomAnimationEffect.hxx,v $
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>
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
;
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;
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
);
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 );
179 const ::com::sun::star::uno::Reference
< ::com::sun::star::animations::XAudio
>& getAudio() const { return mxAudio
; }
181 EffectSequenceHelper
* getEffectSequence() const { return mpEffectSequence
; }
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;
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
);
196 void setEffectSequence( EffectSequenceHelper
* pSequence
) { mpEffectSequence
= pSequence
; }
199 sal_Int16 mnNodeType
;
200 rtl::OUString maPresetId
;
201 rtl::OUString maPresetSubType
;
202 rtl::OUString maProperty
;
203 sal_Int16 mnPresetClass
;
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
208 sal_Int16 mnIterateType
;
209 double mfIterateInterval
;
210 sal_Int32 mnParaDepth
;
212 double mfAcceleration
;
214 sal_Bool mbAutoReverse
;
215 sal_Int16 mnTargetSubItem
;
218 EffectSequenceHelper
* mpEffectSequence
;
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
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
;
254 CustomAnimationTextGroup( const ::com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& rTarget
, sal_Int32 nGroupId
);
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
; }
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];
282 typedef boost::shared_ptr
< CustomAnimationTextGroup
> CustomAnimationTextGroupPtr
;
283 typedef std::map
< sal_Int32
, CustomAnimationTextGroupPtr
> CustomAnimationTextGroupMap
;
285 class EffectSequenceHelper
287 friend class MainSequence
;
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;
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();
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
;
375 class InteractiveSequence
: public EffectSequenceHelper
377 friend class MainSequence
;
378 friend class MainSequenceChangeGuard
;
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();
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
;
403 MainSequence( const ::com::sun::star::uno::Reference
< ::com::sun::star::animations::XAnimationNode
>& xTimingRootNode
);
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;
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. */
439 void unlockRebuilds();
441 DECL_LINK( onTimerHdl
, Timer
* );
443 virtual void implRebuild();
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
;
460 long mnRebuildLockGuard
;
461 bool mbPendingRebuildRequest
;
462 sal_Int32 mbIgnoreChanges
;
465 typedef boost::shared_ptr
< MainSequence
> MainSequencePtr
;
467 class MainSequenceRebuildGuard
470 MainSequenceRebuildGuard( const MainSequencePtr
& pMainSequence
);
471 ~MainSequenceRebuildGuard();
474 MainSequencePtr mpMainSequence
;
479 #endif // _SD_CUSTOMANIMATIONEFFECT_HXX