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 rtl::OUString& getPresetId() const { return maPresetId; }
76 0 : const rtl::OUString& getPresetSubType() const { return maPresetSubType; }
77 0 : const rtl::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 rtl::OUString& rAttributeName, EValue eValue );
139 : bool setProperty( sal_Int32 nNodeType, const rtl::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 : ::rtl::OUString getPath() const;
157 : void setPath( const ::rtl::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 : rtl::OUString maPresetId;
189 : rtl::OUString maPresetSubType;
190 : rtl::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 11 : class ISequenceListener
230 : {
231 : public:
232 : virtual void notify_change() = 0;
233 :
234 : protected:
235 11 : ~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 rtl::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 0 : EffectSequence::iterator getBegin() { return maEffects.begin(); }
320 0 : EffectSequence::iterator getEnd() { return maEffects.end(); }
321 : EffectSequence::iterator find( const CustomAnimationEffectPtr& pEffect );
322 :
323 0 : 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 : ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > createParallelTimeContainer() const;
354 :
355 : void updateTextGroups();
356 :
357 : protected:
358 : ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > mxSequenceRoot;
359 : EffectSequence maEffects;
360 : std::list< ISequenceListener* > maListeners;
361 : CustomAnimationTextGroupMap maGroupMap;
362 : sal_Int32 mnSequenceType;
363 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > mxEventSource;
364 : };
365 :
366 : class MainSequence;
367 :
368 0 : class InteractiveSequence : public EffectSequenceHelper
369 : {
370 : friend class MainSequence;
371 : friend class MainSequenceChangeGuard;
372 :
373 : public:
374 : InteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence );
375 :
376 : /** this method rebuilds the animation nodes */
377 : virtual void rebuild();
378 :
379 : private:
380 : virtual void implRebuild();
381 :
382 : MainSequence* mpMainSequence;
383 : };
384 :
385 : typedef boost::shared_ptr< InteractiveSequence > InteractiveSequencePtr;
386 : typedef std::list< InteractiveSequencePtr > InteractiveSequenceList;
387 :
388 : class MainSequence : public EffectSequenceHelper, public ISequenceListener
389 : {
390 : friend class UndoAnimation;
391 : friend class MainSequenceRebuildGuard;
392 : friend class MainSequenceChangeGuard;
393 :
394 : public:
395 : MainSequence();
396 : MainSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode );
397 : ~MainSequence();
398 :
399 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > getRootNode();
400 : void reset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xTimingRootNode );
401 :
402 : /** this method rebuilds the animation nodes */
403 : virtual void rebuild();
404 :
405 : virtual CustomAnimationEffectPtr findEffect( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode ) const;
406 :
407 : virtual bool disposeShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
408 : virtual void insertTextRange( const com::sun::star::uno::Any& aTarget );
409 : virtual void disposeTextRange( const com::sun::star::uno::Any& aTarget );
410 : virtual bool hasEffect( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
411 : virtual void onTextChanged( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
412 :
413 0 : const InteractiveSequenceList& getInteractiveSequenceList() const { return maInteractiveSequenceList; }
414 :
415 : virtual void notify_change();
416 :
417 : bool setTrigger( const CustomAnimationEffectPtr& pEffect, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xTriggerShape );
418 :
419 : /** starts a timer that recreates the internal structure from the API core after 1 second */
420 : void startRecreateTimer();
421 :
422 : /** starts a timer that rebuilds the API core from the internal structure after 1 second */
423 : void startRebuildTimer();
424 :
425 : virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
426 : virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
427 :
428 : protected:
429 : /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
430 : process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
431 : void lockRebuilds();
432 : void unlockRebuilds();
433 :
434 : DECL_LINK(onTimerHdl, void *);
435 :
436 : virtual void implRebuild();
437 :
438 : void init();
439 :
440 : void createMainSequence();
441 : virtual void reset();
442 :
443 : InteractiveSequencePtr createInteractiveSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape );
444 :
445 : InteractiveSequenceList maInteractiveSequenceList;
446 :
447 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener > mxChangesListener;
448 : ::com::sun::star::uno::Reference< ::com::sun::star::animations::XTimeContainer > mxTimingRootNode;
449 : Timer maTimer;
450 : bool mbTimerMode;
451 : bool mbRebuilding;
452 :
453 : long mnRebuildLockGuard;
454 : bool mbPendingRebuildRequest;
455 : sal_Int32 mbIgnoreChanges;
456 : };
457 :
458 : typedef boost::shared_ptr< MainSequence > MainSequencePtr;
459 :
460 : class MainSequenceRebuildGuard
461 : {
462 : public:
463 : MainSequenceRebuildGuard( const MainSequencePtr& pMainSequence );
464 : ~MainSequenceRebuildGuard();
465 :
466 : private:
467 : MainSequencePtr mpMainSequence;
468 : };
469 :
470 : }
471 :
472 : #endif // _SD_CUSTOMANIMATIONEFFECT_HXX
473 :
474 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|