Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/inc/CustomAnimationEffect.hxx
Line
Count
Source
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
#pragma once
21
22
#include <com/sun/star/animations/XAnimationNode.hpp>
23
#include <com/sun/star/animations/XTimeContainer.hpp>
24
#include <com/sun/star/animations/XAudio.hpp>
25
#include <com/sun/star/drawing/XShape.hpp>
26
#include <com/sun/star/util/XChangesListener.hpp>
27
#include <rtl/ref.hxx>
28
#include <vcl/timer.hxx>
29
#include <tools/long.hxx>
30
#include "sddllapi.h"
31
#include <list>
32
#include <vector>
33
#include <map>
34
#include <memory>
35
36
class SdrPathObj;
37
class SdrModel;
38
39
namespace sd {
40
41
enum class EValue { To, By };
42
43
class CustomAnimationEffect;
44
45
class CustomAnimationPreset;
46
typedef std::shared_ptr< CustomAnimationPreset > CustomAnimationPresetPtr;
47
48
typedef std::shared_ptr< CustomAnimationEffect > CustomAnimationEffectPtr;
49
50
typedef std::list< CustomAnimationEffectPtr > EffectSequence;
51
52
class EffectSequenceHelper;
53
54
class CustomAnimationEffect final
55
{
56
    friend class MainSequence;
57
    friend class EffectSequenceHelper;
58
59
public:
60
    CustomAnimationEffect( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
61
    ~CustomAnimationEffect();
62
63
0
    const css::uno::Reference< css::animations::XAnimationNode >& getNode() const { return mxNode; }
64
    void setNode( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
65
    void replaceNode( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
66
67
    CustomAnimationEffectPtr clone() const;
68
69
    // attributes
70
0
    const OUString&    getPresetId() const { return maPresetId; }
71
0
    const OUString&    getPresetSubType() const { return maPresetSubType; }
72
0
    const OUString&    getProperty() const { return maProperty; }
73
74
0
    sal_Int16       getPresetClass() const { return mnPresetClass; }
75
    void            setPresetClassAndId( sal_Int16 nPresetClass, const OUString& rPresetId );
76
77
30
    sal_Int16       getNodeType() const { return mnNodeType; }
78
    void                           setNodeType( sal_Int16 nNodeType );
79
80
    css::uno::Any   getRepeatCount() const;
81
    void            setRepeatCount( const css::uno::Any& rRepeatCount );
82
83
    css::uno::Any   getEnd() const;
84
    void            setEnd( const css::uno::Any& rEnd );
85
86
0
    sal_Int16       getFill() const { return mnFill; }
87
    void            setFill( sal_Int16 nFill );
88
89
0
    double          getBegin() const { return mfBegin; }
90
    void                           setBegin( double fBegin );
91
92
0
    double          getDuration() const { return mfDuration; }
93
    void                           setDuration( double fDuration );
94
95
0
    double          getAbsoluteDuration() const { return mfAbsoluteDuration; }
96
97
0
    sal_Int16       getIterateType() const { return mnIterateType; }
98
    void                           setIterateType( sal_Int16 nIterateType );
99
100
0
    double          getIterateInterval() const { return mfIterateInterval; }
101
    void                           setIterateInterval( double fIterateInterval );
102
103
233
    const css::uno::Any& getTarget() const { return maTarget; }
104
    void                          setTarget( const css::uno::Any& rTarget );
105
106
0
    bool             hasAfterEffect() const { return mbHasAfterEffect; }
107
0
    void            setHasAfterEffect( bool bHasAfterEffect ) { mbHasAfterEffect = bHasAfterEffect; }
108
109
0
    const css::uno::Any& getDimColor() const { return maDimColor; }
110
0
    void            setDimColor( const css::uno::Any& rDimColor ) { maDimColor = rDimColor; }
111
112
0
    bool            IsAfterEffectOnNext() const { return mbAfterEffectOnNextEffect; }
113
0
    void            setAfterEffectOnNext( bool bOnNextEffect ) { mbAfterEffectOnNextEffect = bOnNextEffect; }
114
115
15
    sal_Int32       getParaDepth() const { return mnParaDepth; }
116
117
0
    bool            hasText() const { return mbHasText; }
118
119
0
    sal_Int16       getCommand() const { return mnCommand; }
120
121
0
    double          getAcceleration() const { return mfAcceleration; }
122
    void            setAcceleration( double fAcceleration );
123
124
0
    double          getDecelerate() const { return mfDecelerate; }
125
    void            setDecelerate( double fDecelerate );
126
127
0
    bool            getAutoReverse() const { return mbAutoReverse; }
128
    void            setAutoReverse( bool bAutoReverse );
129
130
    css::uno::Any  getProperty( sal_Int32 nNodeType, std::u16string_view rAttributeName, EValue eValue );
131
    bool           setProperty( sal_Int32 nNodeType, std::u16string_view rAttributeName, EValue eValue, const css::uno::Any& rValue );
132
133
    css::uno::Any  getTransformationProperty( sal_Int32 nTransformType, EValue eValue );
134
    bool           setTransformationProperty( sal_Int32 nTransformType, EValue eValue, const css::uno::Any& rValue );
135
136
    css::uno::Any  getColor( sal_Int32 nIndex );
137
    void            setColor( sal_Int32 nIndex, const css::uno::Any& rColor );
138
139
260
    sal_Int32       getGroupId() const { return mnGroupId; }
140
    void            setGroupId( sal_Int32 nGroupId );
141
142
218
    sal_Int16       getTargetSubItem() const { return mnTargetSubItem; }
143
    void                           setTargetSubItem( sal_Int16 nSubItem );
144
145
    OUString getPath() const;
146
    void setPath( const OUString& rPath );
147
148
    bool checkForText( const std::vector<sal_Int32>* paragraphNumberingLevel = nullptr );
149
    bool calculateIterateDuration();
150
151
    void setAudio( const css::uno::Reference< css::animations::XAudio >& xAudio );
152
    bool getStopAudio() const;
153
    void setStopAudio();
154
    void createAudio( const css::uno::Any& rSource );
155
    void removeAudio();
156
0
    const css::uno::Reference< css::animations::XAudio >& getAudio() const { return mxAudio; }
157
158
0
    EffectSequenceHelper*   getEffectSequence() const { return mpEffectSequence; }
159
160
    // helper
161
    /// @throws css::uno::Exception
162
    css::uno::Reference< css::animations::XAnimationNode > createAfterEffectNode() const;
163
    css::uno::Reference< css::drawing::XShape > getTargetShape() const;
164
165
    // static helpers
166
    static sal_Int32 get_node_type( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
167
    static sal_Int32 getNumberOfSubitems( const css::uno::Any& aTarget, sal_Int16 nIterateType );
168
169
    rtl::Reference<SdrPathObj> createSdrPathObjFromPath(SdrModel& rTargetModel);
170
    void updateSdrPathObjFromPath( SdrPathObj& rPathObj );
171
    void updatePathFromSdrPathObj( const SdrPathObj& rPathObj );
172
173
private:
174
520
    void setEffectSequence( EffectSequenceHelper* pSequence ) { mpEffectSequence = pSequence; }
175
176
    sal_Int16       mnNodeType;
177
    OUString        maPresetId;
178
    OUString        maPresetSubType;
179
    OUString        maProperty;
180
    sal_Int16       mnPresetClass;
181
    sal_Int16       mnFill;
182
    double          mfBegin;
183
    double          mfDuration;                 // this is the maximum duration of the subeffects
184
    double          mfAbsoluteDuration;         // this is the maximum duration of the subeffects including possible iterations
185
    sal_Int32       mnGroupId;
186
    sal_Int16       mnIterateType;
187
    double          mfIterateInterval;
188
    sal_Int32       mnParaDepth;
189
    bool            mbHasText;
190
    double          mfAcceleration;
191
    double          mfDecelerate;
192
    bool            mbAutoReverse;
193
    sal_Int16       mnTargetSubItem;
194
    sal_Int16       mnCommand;
195
196
    EffectSequenceHelper* mpEffectSequence;
197
198
    css::uno::Reference< css::animations::XAnimationNode > mxNode;
199
    css::uno::Reference< css::animations::XAudio > mxAudio;
200
    css::uno::Any maTarget;
201
202
    bool        mbHasAfterEffect;
203
    css::uno::Any maDimColor;
204
    bool        mbAfterEffectOnNextEffect;
205
};
206
207
struct stl_CustomAnimationEffect_search_node_predict
208
{
209
    stl_CustomAnimationEffect_search_node_predict( const css::uno::Reference< css::animations::XAnimationNode >& xSearchNode );
210
    bool operator()( const CustomAnimationEffectPtr& pEffect ) const;
211
    const css::uno::Reference< css::animations::XAnimationNode >& mxSearchNode;
212
};
213
214
/** this listener is implemented by UI components to track changes in the animation core */
215
class ISequenceListener
216
{
217
public:
218
    virtual void notify_change() = 0;
219
220
protected:
221
3.09k
    ~ISequenceListener() {}
222
};
223
224
/** this class keeps track of a group of animations that build up
225
    a text animation for a single shape */
226
class CustomAnimationTextGroup
227
{
228
    friend class EffectSequenceHelper;
229
230
public:
231
    CustomAnimationTextGroup( const css::uno::Reference< css::drawing::XShape >& rTarget, sal_Int32 nGroupId );
232
233
    void reset();
234
    void addEffect( CustomAnimationEffectPtr const & pEffect );
235
236
0
    const EffectSequence& getEffects() const { return maEffects; }
237
238
    /* -1: as single object, 0: all at once, n > 0: by n Th paragraph */
239
0
    sal_Int32 getTextGrouping() const { return mnTextGrouping; }
240
241
0
    bool getAnimateForm() const { return mbAnimateForm; }
242
0
    bool getTextReverse() const { return mbTextReverse; }
243
0
    double getTextGroupingAuto() const { return mfGroupingAuto; }
244
245
private:
246
    EffectSequence maEffects;
247
    css::uno::Reference< css::drawing::XShape > maTarget;
248
249
    enum { PARA_LEVELS = 5 };
250
251
    sal_Int32 mnTextGrouping;
252
    bool mbAnimateForm;
253
    bool mbTextReverse;
254
    double mfGroupingAuto;
255
    sal_Int32 mnLastPara;
256
    sal_Int8 mnDepthFlags[PARA_LEVELS];
257
    sal_Int32 mnGroupId;
258
};
259
260
typedef std::shared_ptr< CustomAnimationTextGroup > CustomAnimationTextGroupPtr;
261
typedef std::map< sal_Int32, CustomAnimationTextGroupPtr > CustomAnimationTextGroupMap;
262
263
class SD_DLLPUBLIC EffectSequenceHelper
264
{
265
friend class MainSequence;
266
267
public:
268
    SAL_DLLPRIVATE EffectSequenceHelper();
269
    SAL_DLLPRIVATE EffectSequenceHelper( css::uno::Reference< css::animations::XTimeContainer > xSequenceRoot );
270
    SAL_DLLPRIVATE virtual ~EffectSequenceHelper();
271
272
    SAL_DLLPRIVATE virtual css::uno::Reference< css::animations::XAnimationNode > getRootNode();
273
274
    SAL_DLLPRIVATE CustomAnimationEffectPtr append( const CustomAnimationPresetPtr& pDescriptor, const css::uno::Any& rTarget, double fDuration );
275
    SAL_DLLPRIVATE CustomAnimationEffectPtr append( const SdrPathObj& rPathObj, const css::uno::Any& rTarget, double fDuration, const OUString& rPresetId );
276
    void append( const CustomAnimationEffectPtr& pEffect );
277
    SAL_DLLPRIVATE void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, double fDuration );
278
    SAL_DLLPRIVATE void replace( const CustomAnimationEffectPtr& pEffect, const CustomAnimationPresetPtr& pDescriptor, const OUString& rPresetSubType, double fDuration );
279
    SAL_DLLPRIVATE void remove( const CustomAnimationEffectPtr& pEffect );
280
    SAL_DLLPRIVATE void moveToBeforeEffect( const CustomAnimationEffectPtr& pEffect,  const CustomAnimationEffectPtr& pInsertBefore);
281
282
    SAL_DLLPRIVATE void create( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
283
    SAL_DLLPRIVATE void createEffectsequence( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
284
    SAL_DLLPRIVATE void processAfterEffect( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
285
    SAL_DLLPRIVATE void createEffects( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
286
287
0
    SAL_DLLPRIVATE sal_Int32 getCount() const { return sal::static_int_cast< sal_Int32 >( maEffects.size() ); }
288
289
    SAL_DLLPRIVATE virtual CustomAnimationEffectPtr findEffect( const css::uno::Reference< css::animations::XAnimationNode >& xNode ) const;
290
291
    SAL_DLLPRIVATE virtual bool disposeShape( const css::uno::Reference< css::drawing::XShape >& xShape );
292
    SAL_DLLPRIVATE virtual void insertTextRange( const css::uno::Any& aTarget );
293
    SAL_DLLPRIVATE virtual void disposeTextRange( const css::uno::Any& aTarget );
294
    SAL_DLLPRIVATE virtual bool hasEffect( const css::uno::Reference< css::drawing::XShape >& xShape );
295
    SAL_DLLPRIVATE virtual void onTextChanged( const css::uno::Reference< css::drawing::XShape >& xShape );
296
297
    /** this method rebuilds the animation nodes */
298
    SAL_DLLPRIVATE virtual void rebuild();
299
300
0
    SAL_DLLPRIVATE EffectSequence::iterator getBegin() { return maEffects.begin(); }
301
0
    SAL_DLLPRIVATE EffectSequence::iterator getEnd() { return maEffects.end(); }
302
    SAL_DLLPRIVATE EffectSequence::iterator find( const CustomAnimationEffectPtr& pEffect );
303
304
0
    SAL_DLLPRIVATE EffectSequence& getSequence() { return maEffects; }
305
306
    SAL_DLLPRIVATE void addListener( ISequenceListener* pListener );
307
    SAL_DLLPRIVATE void removeListener( ISequenceListener* pListener );
308
309
    // text group methods
310
311
    SAL_DLLPRIVATE CustomAnimationTextGroupPtr findGroup( sal_Int32 nGroupId );
312
    CustomAnimationTextGroupPtr createTextGroup(const CustomAnimationEffectPtr& pEffect,
313
                                                sal_Int32 nTextGrouping, double fTextGroupingAuto,
314
                                                bool bAnimateForm, bool bTextReverse);
315
    SAL_DLLPRIVATE void setTextGrouping( const CustomAnimationTextGroupPtr& pTextGroup, sal_Int32 nTextGrouping );
316
    SAL_DLLPRIVATE void setAnimateForm( const CustomAnimationTextGroupPtr& pTextGroup, bool bAnimateForm );
317
    SAL_DLLPRIVATE void setTextGroupingAuto( const CustomAnimationTextGroupPtr& pTextGroup, double fTextGroupingAuto );
318
    SAL_DLLPRIVATE void setTextReverse( const  CustomAnimationTextGroupPtr& pTextGroup, bool bAnimateForm );
319
320
0
    SAL_DLLPRIVATE sal_Int32 getSequenceType() const { return mnSequenceType; }
321
322
0
    SAL_DLLPRIVATE const css::uno::Reference< css::drawing::XShape >& getTriggerShape() const { return mxEventSource; }
323
0
    SAL_DLLPRIVATE void setTriggerShape( const css::uno::Reference< css::drawing::XShape >& xTrigger ) { mxEventSource = xTrigger; }
324
325
    SAL_DLLPRIVATE virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const;
326
    SAL_DLLPRIVATE virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const;
327
328
protected:
329
    SAL_DLLPRIVATE virtual void implRebuild();
330
    SAL_DLLPRIVATE virtual void reset();
331
332
    SAL_DLLPRIVATE void createTextGroupParagraphEffects( const CustomAnimationTextGroupPtr& pTextGroup, const CustomAnimationEffectPtr& pEffect, bool bUsed );
333
334
    SAL_DLLPRIVATE void notify_listeners();
335
336
    SAL_DLLPRIVATE void updateTextGroups();
337
338
    SAL_DLLPRIVATE bool getParagraphNumberingLevels( const css::uno::Reference< css::drawing::XShape >& xShape, std::vector< sal_Int32 >& rParagraphNumberingLevel );
339
340
protected:
341
    css::uno::Reference< css::animations::XTimeContainer > mxSequenceRoot;
342
    EffectSequence maEffects;
343
    std::list< ISequenceListener* > maListeners;
344
    CustomAnimationTextGroupMap maGroupMap;
345
    sal_Int32 mnSequenceType;
346
    css::uno::Reference< css::drawing::XShape > mxEventSource;
347
};
348
349
class MainSequence;
350
351
class InteractiveSequence final : public EffectSequenceHelper
352
{
353
friend class MainSequence;
354
friend class MainSequenceChangeGuard;
355
356
public:
357
    InteractiveSequence( const css::uno::Reference< css::animations::XTimeContainer >& xSequenceRoot, MainSequence* pMainSequence );
358
359
    /** this method rebuilds the animation nodes */
360
    virtual void rebuild() override;
361
362
private:
363
    virtual void implRebuild() override;
364
365
    MainSequence*   mpMainSequence;
366
};
367
368
typedef std::shared_ptr< InteractiveSequence > InteractiveSequencePtr;
369
typedef std::vector< InteractiveSequencePtr > InteractiveSequenceVector;
370
371
class MainSequence final : public EffectSequenceHelper, public ISequenceListener
372
{
373
    friend class UndoAnimation;
374
    friend class MainSequenceRebuildGuard;
375
    friend class MainSequenceChangeGuard;
376
377
public:
378
    MainSequence();
379
    MainSequence( const css::uno::Reference< css::animations::XAnimationNode >& xTimingRootNode );
380
    virtual ~MainSequence() override;
381
382
    virtual css::uno::Reference< css::animations::XAnimationNode > getRootNode() override;
383
    void reset( const css::uno::Reference< css::animations::XAnimationNode >& xTimingRootNode );
384
385
    /** this method rebuilds the animation nodes */
386
    virtual void rebuild() override;
387
388
    virtual CustomAnimationEffectPtr findEffect( const css::uno::Reference< css::animations::XAnimationNode >& xNode ) const override;
389
390
    virtual bool disposeShape( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
391
    virtual void insertTextRange( const css::uno::Any& aTarget ) override;
392
    virtual void disposeTextRange( const css::uno::Any& aTarget ) override;
393
    virtual bool hasEffect( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
394
    virtual void onTextChanged( const css::uno::Reference< css::drawing::XShape >& xShape ) override;
395
396
0
    const InteractiveSequenceVector& getInteractiveSequenceVector() const { return maInteractiveSequenceVector; }
397
398
    virtual void notify_change() override;
399
400
    bool setTrigger( const CustomAnimationEffectPtr& pEffect, const css::uno::Reference< css::drawing::XShape >& xTriggerShape );
401
402
    /** starts a timer that recreates the internal structure from the API core after 1 second */
403
    void startRecreateTimer();
404
405
    /** starts a timer that rebuilds the API core from the internal structure after 1 second */
406
    void startRebuildTimer();
407
408
    virtual sal_Int32 getOffsetFromEffect( const CustomAnimationEffectPtr& xEffect ) const override;
409
    virtual CustomAnimationEffectPtr getEffectFromOffset( sal_Int32 nOffset ) const override;
410
411
private:
412
    /** permits rebuilds until unlockRebuilds() is called. All rebuild calls during a locked sequence are
413
        process after unlockRebuilds() call. lockRebuilds() and unlockRebuilds() calls can be nested. */
414
    void lockRebuilds();
415
    void unlockRebuilds();
416
417
    DECL_LINK(onTimerHdl, Timer *, void);
418
419
    virtual void implRebuild() override;
420
421
    void init();
422
423
    void createMainSequence();
424
    virtual void reset() override;
425
426
    InteractiveSequencePtr createInteractiveSequence( const css::uno::Reference< css::drawing::XShape >& xShape );
427
428
    InteractiveSequenceVector maInteractiveSequenceVector;
429
430
    css::uno::Reference< css::util::XChangesListener > mxChangesListener;
431
    css::uno::Reference< css::animations::XTimeContainer > mxTimingRootNode;
432
    Timer maTimer;
433
    bool mbTimerMode;
434
    bool mbRebuilding;
435
436
    ::tools::Long mnRebuildLockGuard;
437
    bool mbPendingRebuildRequest;
438
    sal_Int32 mbIgnoreChanges;
439
};
440
441
typedef std::shared_ptr< MainSequence > MainSequencePtr;
442
443
class MainSequenceRebuildGuard
444
{
445
public:
446
    MainSequenceRebuildGuard( MainSequencePtr pMainSequence );
447
    ~MainSequenceRebuildGuard();
448
449
private:
450
    MainSequencePtr mpMainSequence;
451
};
452
453
}
454
455
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */