Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _SD_CUSTOMANIMATIONEFFECT_HXX
21 : #define _SD_CUSTOMANIMATIONEFFECT_HXX
22 :
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>
29 :
30 : #include <boost/shared_ptr.hpp>
31 :
32 : #include <comphelper/stl_types.hxx>
33 : #include <vcl/timer.hxx>
34 :
35 : #include <sddllapi.h>
36 :
37 : #include <list>
38 : #include <map>
39 :
40 : class SdrPathObj;
41 :
42 : namespace sd {
43 :
44 : // --------------------------------------------------------------------
45 :
46 : enum EValue { VALUE_FROM, VALUE_TO, VALUE_BY, VALUE_FIRST, VALUE_LAST };
47 :
48 : class CustomAnimationEffect;
49 :
50 : class CustomAnimationPreset;
51 : typedef boost::shared_ptr< CustomAnimationPreset > CustomAnimationPresetPtr;
52 :
53 : typedef boost::shared_ptr< CustomAnimationEffect > CustomAnimationEffectPtr;
54 :
55 : typedef std::list< CustomAnimationEffectPtr > EffectSequence;
56 :
57 : class EffectSequenceHelper;
58 :
59 : class CustomAnimationEffect
60 : {
61 : friend class MainSequence;
62 : friend class EffectSequenceHelper;
63 :
64 : public:
65 : SD_DLLPUBLIC CustomAnimationEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode );
66 : SD_DLLPUBLIC virtual ~CustomAnimationEffect();
67 :
68 0 : 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 );
71 :
72 : CustomAnimationEffectPtr clone() const;
73 :
74 : // attributes
75 0 : const OUString& getPresetId() const { return maPresetId; }
76 0 : const OUString& getPresetSubType() const { return maPresetSubType; }
77 0 : const OUString& getProperty() const { return maProperty; }
78 :
79 0 : sal_Int16 getPresetClass() const { return mnPresetClass; }
80 : void setPresetClass( sal_Int16 nPresetClass );
81 :
82 0 : sal_Int16 getNodeType() const { return mnNodeType; }
83 : SD_DLLPUBLIC void setNodeType( sal_Int16 nNodeType );
84 :
85 : ::com::sun::star::uno::Any getRepeatCount() const;
86 : void setRepeatCount( const ::com::sun::star::uno::Any& rRepeatCount );
87 :
88 : ::com::sun::star::uno::Any getEnd() const;
89 : void setEnd( const ::com::sun::star::uno::Any& rEnd );
90 :
91 : sal_Int16 getFill() const;
92 : void setFill( sal_Int16 nFill );
93 :
94 0 : double getBegin() const { return mfBegin; }
95 : SD_DLLPUBLIC void setBegin( double fBegin );
96 :
97 0 : double getDuration() const { return mfDuration; }
98 : SD_DLLPUBLIC void setDuration( double fDuration );
99 :
100 0 : double getAbsoluteDuration() const { return mfAbsoluteDuration; }
101 :
102 : const String& getName() const { return maName; }
103 : void setName( const String& rName ) { maName = rName; }
104 :
105 0 : sal_Int16 getIterateType() const { return mnIterateType; }
106 : SD_DLLPUBLIC void setIterateType( sal_Int16 nIterateType );
107 :
108 0 : double getIterateInterval() const { return mfIterateInterval; }
109 : SD_DLLPUBLIC void setIterateInterval( double fIterateInterval );
110 :
111 0 : ::com::sun::star::uno::Any getTarget() const { return maTarget; }
112 : SD_DLLPUBLIC void setTarget( const ::com::sun::star::uno::Any& rTarget );
113 :
114 0 : sal_Bool hasAfterEffect() const { return mbHasAfterEffect; }
115 0 : void setHasAfterEffect( sal_Bool bHasAfterEffect ) { mbHasAfterEffect = bHasAfterEffect; }
116 :
117 0 : ::com::sun::star::uno::Any getDimColor() const { return maDimColor; }
118 0 : void setDimColor( ::com::sun::star::uno::Any aDimColor ) { maDimColor = aDimColor; }
119 :
120 0 : bool IsAfterEffectOnNext() const { return mbAfterEffectOnNextEffect; }
121 0 : void setAfterEffectOnNext( bool bOnNextEffect ) { mbAfterEffectOnNextEffect = bOnNextEffect; }
122 :
123 0 : sal_Int32 getParaDepth() const { return mnParaDepth; }
124 :
125 0 : sal_Bool hasText() const { return mbHasText; }
126 :
127 0 : sal_Int16 getCommand() const { return mnCommand; }
128 :
129 0 : double getAcceleration() const { return mfAcceleration; }
130 : void setAcceleration( double fAcceleration );
131 :
132 0 : double getDecelerate() const { return mfDecelerate; }
133 : void setDecelerate( double fDecelerate );
134 :
135 0 : sal_Bool getAutoReverse() const { return mbAutoReverse; }
136 : void setAutoReverse( sal_Bool bAutoReverse );
137 :
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 );
140 :
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 );
143 :
144 : ::com::sun::star::uno::Any getColor( sal_Int32 nIndex );
145 : void setColor( sal_Int32 nIndex, const ::com::sun::star::uno::Any& rColor );
146 :
147 : ::com::sun::star::uno::Any getRotation();
148 : void setRotation( const ::com::sun::star::uno::Any& rRotation );
149 :
150 0 : sal_Int32 getGroupId() const { return mnGroupId; }
151 : void setGroupId( sal_Int32 nGroupId );
152 :
153 0 : sal_Int16 getTargetSubItem() const { return mnTargetSubItem; }
154 : SD_DLLPUBLIC void setTargetSubItem( sal_Int16 nSubItem );
155 :
156 : OUString getPath() const;
157 : void setPath( const OUString& rPath );
158 :
159 : bool checkForText();
160 : bool calculateIterateDuration();
161 :
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 0 : const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAudio >& getAudio() const { return mxAudio; }
168 :
169 0 : EffectSequenceHelper* getEffectSequence() const { return mpEffectSequence; }
170 :
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;
174 :
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 );
178 :
179 : SdrPathObj* createSdrPathObjFromPath();
180 : void updateSdrPathObjFromPath( SdrPathObj& rPathObj );
181 : void updatePathFromSdrPathObj( const SdrPathObj& rPathObj );
182 :
183 : protected:
184 0 : void setEffectSequence( EffectSequenceHelper* pSequence ) { mpEffectSequence = pSequence; }
185 :
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;
205 :
206 : EffectSequenceHelper* mpEffectSequence;
207 :
208 : String maName;
209 :
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;
213 :
214 : sal_Bool mbHasAfterEffect;
215 : ::com::sun::star::uno::Any maDimColor;
216 : bool mbAfterEffectOnNextEffect;
217 : };
218 :
219 : struct stl_CustomAnimationEffect_search_node_predict
220 : {
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;
224 : };
225 :
226 : enum ESequenceHint { EFFECT_EDITED, EFFECT_REMOVED, EFFECT_ADDED };
227 :
228 : /** this listener is implemented by UI components to track changes in the animation core */
229 78 : class ISequenceListener
230 : {
231 : public:
232 : virtual void notify_change() = 0;
233 :
234 : protected:
235 78 : ~ISequenceListener() {}
236 : };
237 :
238 : /** this class keeps track of a group of animations that build up
239 : a text animation for a single shape */
240 0 : class CustomAnimationTextGroup
241 : {
242 : friend class EffectSequenceHelper;
243 :
244 : public:
245 : CustomAnimationTextGroup( const ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rTarget, sal_Int32 nGroupId );
246 :
247 : void reset();
248 : void addEffect( CustomAnimationEffectPtr& pEffect );
249 :
250 : const ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& getTarget() const { return maTarget; }
251 0 : const EffectSequence& getEffects() const { return maEffects; }
252 :
253 : /* -1: as single object, 0: all at once, n > 0: by n Th paragraph */
254 0 : sal_Int32 getTextGrouping() const { return mnTextGrouping; }
255 :
256 0 : sal_Bool getAnimateForm() const { return mbAnimateForm; }
257 0 : sal_Bool getTextReverse() const { return mbTextReverse; }
258 0 : double getTextGroupingAuto() const { return mfGroupingAuto; }
259 :
260 : private:
261 : EffectSequence maEffects;
262 : ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape > maTarget;
263 :
264 : enum { PARA_LEVELS = 5 };
265 :
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;
273 : };
274 :
275 : typedef boost::shared_ptr< CustomAnimationTextGroup > CustomAnimationTextGroupPtr;
276 : typedef std::map< sal_Int32, CustomAnimationTextGroupPtr > CustomAnimationTextGroupMap;
277 :
278 : class EffectSequenceHelper
279 : {
280 : friend class MainSequence;
281 :
282 : public:
283 : EffectSequenceHelper();
284 : EffectSequenceHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot );
285 : virtual ~EffectSequenceHelper();
286 :
287 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > getRootNode();
288 :
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 );
296 :
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 );
301 :
302 0 : sal_Int32 getCount() const { return sal::static_int_cast< sal_Int32 >( maEffects.size() ); }
303 :
304 : virtual CustomAnimationEffectPtr findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const;
305 :
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 );
311 :
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 );
315 :
316 : /** this method rebuilds the animation nodes */
317 : virtual void rebuild();
318 :
319 350 : EffectSequence::iterator getBegin() { return maEffects.begin(); }
320 352 : EffectSequence::iterator getEnd() { return maEffects.end(); }
321 : EffectSequence::iterator find( const CustomAnimationEffectPtr& pEffect );
322 :
323 2 : EffectSequence& getSequence() { return maEffects; }
324 :
325 : void addListener( ISequenceListener* pListener );
326 : void removeListener( ISequenceListener* pListener );
327 :
328 : // text group methods
329 :
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 );
336 :
337 0 : sal_Int32 getSequenceType() const { return mnSequenceType; }
338 :
339 0 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getTriggerShape() const { return mxEventSource; }
340 0 : void setTriggerShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTrigger ) { mxEventSource = xTrigger; }
341 :
342 : virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
343 : virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
344 :
345 : protected:
346 : virtual void implRebuild();
347 : virtual void reset();
348 :
349 : void createTextGroupParagraphEffects( CustomAnimationTextGroupPtr pTextGroup, CustomAnimationEffectPtr pEffect, bool bUsed );
350 :
351 : void notify_listeners();
352 :
353 : void updateTextGroups();
354 :
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;
362 : };
363 :
364 : class MainSequence;
365 :
366 0 : class InteractiveSequence : public EffectSequenceHelper
367 : {
368 : friend class MainSequence;
369 : friend class MainSequenceChangeGuard;
370 :
371 : public:
372 : InteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence );
373 :
374 : /** this method rebuilds the animation nodes */
375 : virtual void rebuild();
376 :
377 : private:
378 : virtual void implRebuild();
379 :
380 : MainSequence* mpMainSequence;
381 : };
382 :
383 : typedef boost::shared_ptr< InteractiveSequence > InteractiveSequencePtr;
384 : typedef std::list< InteractiveSequencePtr > InteractiveSequenceList;
385 :
386 : class MainSequence : public EffectSequenceHelper, public ISequenceListener
387 : {
388 : friend class UndoAnimation;
389 : friend class MainSequenceRebuildGuard;
390 : friend class MainSequenceChangeGuard;
391 :
392 : public:
393 : MainSequence();
394 : MainSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode );
395 : ~MainSequence();
396 :
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 );
399 :
400 : /** this method rebuilds the animation nodes */
401 : virtual void rebuild();
402 :
403 : virtual CustomAnimationEffectPtr findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const;
404 :
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 );
410 :
411 0 : const InteractiveSequenceList& getInteractiveSequenceList() const { return maInteractiveSequenceList; }
412 :
413 : virtual void notify_change();
414 :
415 : bool setTrigger( const CustomAnimationEffectPtr& pEffect, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTriggerShape );
416 :
417 : /** starts a timer that recreates the internal structure from the API core after 1 second */
418 : void startRecreateTimer();
419 :
420 : /** starts a timer that rebuilds the API core from the internal structure after 1 second */
421 : void startRebuildTimer();
422 :
423 : virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
424 : virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
425 :
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();
431 :
432 : DECL_LINK(onTimerHdl, void *);
433 :
434 : virtual void implRebuild();
435 :
436 : void init();
437 :
438 : void createMainSequence();
439 : virtual void reset();
440 :
441 : InteractiveSequencePtr createInteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape );
442 :
443 : InteractiveSequenceList maInteractiveSequenceList;
444 :
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;
450 :
451 : long mnRebuildLockGuard;
452 : bool mbPendingRebuildRequest;
453 : sal_Int32 mbIgnoreChanges;
454 : };
455 :
456 : typedef boost::shared_ptr< MainSequence > MainSequencePtr;
457 :
458 : class MainSequenceRebuildGuard
459 : {
460 : public:
461 : MainSequenceRebuildGuard( const MainSequencePtr& pMainSequence );
462 : ~MainSequenceRebuildGuard();
463 :
464 : private:
465 : MainSequencePtr mpMainSequence;
466 : };
467 :
468 : }
469 :
470 : #endif // _SD_CUSTOMANIMATIONEFFECT_HXX
471 :
472 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|